我使用Httconnection
连接到网络服务器,somtimes请求失败导致
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");
我在正确处理请求后关闭了所有连接。这个例外是由于超出了最大连接数。
答案 0 :(得分:1)
这是内部服务器错误,返回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
答案 1 :(得分:0)
使用HTTPTransportSE,在调用方法之前写下这个" call"
ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));
transport.call(SOAP_ACTION, envelope, headerPropertyArrayList);