我正在使用Httconnection连接到for服务器,有时请求失败会导致
调用httpconnection.getResponseCode()时的EOFException。
在建立连接时,我设置了以下标头
HttpConnection httpconnection = (HttpConnection) Connector.open(url.concat(";interface=wifi"));
httpconnection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
httpconnection.setRequestProperty("Content-Language", "en-US");我正在关闭所有的连接后,处理的请求properly.Is此异常是由于超过最大连接数。
发布于 2009-10-07 05:53:46
这是一个内部服务器错误,它在响应中返回status code 500。
这可能是由不正确的请求引起的,但也可能是服务器代码或过载造成的。
如果您有权访问服务器,请检查事件日志。
另请参阅
500 EOF when chunk header expected
Why might LWP::UserAgent be failing with '500 EOF'?
500 EOF instead of reponse status line in perl script
Apache 1.3 error - Unexpected EOF reading HTTP status - connectionreset
Error 500!
更新另一方面,如果它不是响应消息,而是一个真正的异常,那么它可能只是一个错误,just like in old java
而解决方法可能是将getResponseCode()放在try/catch中,并在异常时第二次调用:
int responseCode = -1;
try {
responseCode = con.getResponseCode();
} catch (IOException ex1) {
//check if it's eof, if yes retrieve code again
if (-1 != ex1.getMessage().indexOf("EOF")) {
try {
responseCode = con.getResponseCode();
} catch (IOException ex2) {
System.out.println(ex2.getMessage());
// handle exception
}
} else {
System.out.println(ex1.getMessage());
// handle exception
}
}讨论连接数量限制,请阅读
What Is - Maximum number of simultaneous connections
How To - Close connections
发布于 2016-04-20 21:28:57
使用HTTPTransportSE,在调用方法"call“之前编写以下代码
ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
transport.call(SOAP_ACTION, envelope, headerPropertyArrayList);https://stackoverflow.com/questions/1525893
复制相似问题