我正在使用 aHttpClient
向 Web 服务发送SOAP
请求以查询一些数据。对于某些网络服务参数,网络服务的执行时间超过 5 分钟,5 分钟后我得到一个java.net.SocketException: Connection reset
.
我认为发生错误是因为连接空闲超过 5 分钟,然后防火墙限制了连接。
有没有办法为http post请求发送keep-alive包或保持连接活跃的东西?(如果可能的话,我需要一个客户端解决方案)
如果你用谷歌搜索HttpClient keep-alive
你会发现很多关于重用连接的主题。就我而言,我只想保持连接活跃,直到我得到回应。
执行 SOAP 请求的方法:
def executeSOAPRequest(String url, String content, String soapAction, Integer timeout) {
def retVal = new SoapResponse();
PostMethod post = new PostMethod(url);
RequestEntity entity = new StringRequestEntity(content,"ISO-8859-1","ISO-8859-1");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", soapAction);
HttpClient httpclient = new HttpClient()
httpclient.setTimeout(timeout)
try {
retVal.httpResponse = httpclient.executeMethod(post);
retVal.httpResponseBody = post.getResponseBodyAsString();
} catch(Exception e){
... exception handling ...
} finally {
... finally stuff ...
}
return retVal;
}
目前使用的是 HttpClient v3.1。