Web services 连接在一段时间后关闭
我已使用以下代码连接互联网Web services 连接在一段时间后关闭,web-services,blackberry,blackberry-eclipse-plugin,blackberry-jde,j2mepolish,Web Services,Blackberry,Blackberry Eclipse Plugin,Blackberry Jde,J2mepolish,我已使用以下代码连接互联网 HttpConnection httpConn = null; DataOutputStream dataOS = null; redemptionUrl = redemptionUrl+ ";deviceside=true"; httpConn = (HttpConnection) Connector.open(redemptionUrl); httpConn.setRequestProperty("User-Agent", "Profile/MIDP-1.0,
HttpConnection httpConn = null;
DataOutputStream dataOS = null;
redemptionUrl = redemptionUrl+ ";deviceside=true";
httpConn = (HttpConnection) Connector.open(redemptionUrl);
httpConn.setRequestProperty("User-Agent",
"Profile/MIDP-1.0, Configuration/CLDC-1.0");
httpConn.setRequestProperty("Connection", "Keep-Alive");
httpConn.setRequestProperty("Content-Language", "en-US");
httpConn.setRequestMethod(HttpConnection.POST);
dataOS = (DataOutputStream) httpConn.openDataOutputStream();
dataOS.flush();
dataOS.close();
DataInputStream dataIS = (DataInputStream) httpConn
.openDataInputStream();
int ch;
sb = new StringBuffer();
System.out.println("%%%% Me here 4 sb is ::" + sb.toString());
while ((ch = dataIS.read()) != -1) {
sb.append((char) ch);
}
// Respeonse
// -------------------------------------------------------------
System.out.println("sb.toString()::" + sb.toString());
String responseData = sb.toString();
dataIS.close();
httpConn.close();
一段时间后,连接断开。怎么了,有人能帮忙吗
public class HttpPostRetriver extends Thread{
private String _url;
private StringBuffer _postData;
private byte[] _data=new byte[512];
private HttpConnection _httpConnection;
private OutputStream os;
private InputStream is;
public HttpPostRetriver(String url) {
_url = url+UrlSuffix.updataConnectionSuffix();
try {
_httpConnection = (HttpConnection)Connector.open(_url);
} catch(Exception e) {
}
}
public String postData() {
try {
_httpConnection.setRequestMethod(HttpConnection.POST);
_httpConnection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
_httpConnection.setRequestProperty("Content-Language", "en-US");
_httpConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
os = _httpConnection.openOutputStream();
int rc = _httpConnection.getResponseCode();
if(rc == HttpConnection.HTTP_OK) {
is = _httpConnection.openInputStream();
is.read(_data);
} else {
_data = null;
}
} catch(Exception e) {
//exception
}
return (new String(_data));
}
}
请尝试此代码………1)。连接将在多少时间内关闭。。。??2). 什么时候连接将断开“发送数据”或“其他”之间的连接?我在我的应用程序中使用web服务。我可以登录到应用程序,并从web服务获取所有用户数据的响应,然后在这之后获得断开连接,之后当我发送请求时,其请求显示超时