如题Hi,各位朋友:
我遇到一个问题是关于HttpClient自动关闭了连接,部分代码如下:method.addRequestHeader("connection","keep-alive")
method.setRequestHeader("Cookie","JUCSSESSIONID="+JUCSSESSIONID);
LOGGER.info("JUCSSESSIONID="+JUCSSESSIONID);
int statusCode = client.executeMethod(method);
LOGGER.info(statusCode);
if(statusCode == HttpStatus.SC_OK){
LOGGER.info(method.getResponseBodyAsString());
return method.getResponseBodyAsString();
}else{
return null;
}
打印的日志如下(变量statusCode没有在日志中打印出来,连接关闭了):[2013-10-28 08:58:00] INFO [com.epay.utils.sso.UCSUtils] (UCSUtils.java:81) - JUCSSESSIONID=00005Z-xL_aZyM4Ah0p3P2MWgOA:17qh2jfr0
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpConnection] (HttpConnection.java:692) - Open connection to js.10086.cn:80
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpMethodDirector] (HttpMethodDirector.java:404) - Closing the connection.
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpMethodDirector] (HttpMethodDirector.java:434) - Method retry handler returned false. Automatic recovery will not be attempted
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpConnection] (HttpConnection.java:1178) - Releasing connection back to connection manager.
----------------------------------------
请问HttpClient为什么会关闭连接呢?谢谢了!!!HttpClientWeb
我遇到一个问题是关于HttpClient自动关闭了连接,部分代码如下:method.addRequestHeader("connection","keep-alive")
method.setRequestHeader("Cookie","JUCSSESSIONID="+JUCSSESSIONID);
LOGGER.info("JUCSSESSIONID="+JUCSSESSIONID);
int statusCode = client.executeMethod(method);
LOGGER.info(statusCode);
if(statusCode == HttpStatus.SC_OK){
LOGGER.info(method.getResponseBodyAsString());
return method.getResponseBodyAsString();
}else{
return null;
}
打印的日志如下(变量statusCode没有在日志中打印出来,连接关闭了):[2013-10-28 08:58:00] INFO [com.epay.utils.sso.UCSUtils] (UCSUtils.java:81) - JUCSSESSIONID=00005Z-xL_aZyM4Ah0p3P2MWgOA:17qh2jfr0
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpConnection] (HttpConnection.java:692) - Open connection to js.10086.cn:80
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpMethodDirector] (HttpMethodDirector.java:404) - Closing the connection.
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpMethodDirector] (HttpMethodDirector.java:434) - Method retry handler returned false. Automatic recovery will not be attempted
[2013-10-28 08:58:00] DEBUG [org.apache.commons.httpclient.HttpConnection] (HttpConnection.java:1178) - Releasing connection back to connection manager.
----------------------------------------
请问HttpClient为什么会关闭连接呢?谢谢了!!!HttpClientWeb
解决方案 »
- jdbc连接sql2008出错 急急急!!求帮忙 谢谢
- 各位大哥,帮小弟解释一下
- web service
- 网络问题,就一点点,被卡到了,求救`````
- spring高手请进,急!!!!!!!!!!!!!!!!
- 关于程序员的职业规划
- 关于WEBLOGIC的数据源的问题
- 用过XDOCLET的请进!
- 莱鸟爱提问,关于weblogic 中classpath一问(200分。。在线等侯)
- 使用s:iterator遍历嵌套list,EL表达式出错,s:property可以输出
- JPA @OneToOne @PrimaryKeyJoinColumn 延迟加载怎么配置呢?哪位指点下,谢谢。
- 用jaxb2把Map<String,Object>转换为xml
MethodRetryHandler handler =
((HttpMethodBase)method).getMethodRetryHandler();
if (handler != null) {
if (!handler.retryMethod(
method,
this.conn,
new HttpRecoverableException(e.getMessage()),
execCount,
method.isRequestSent())) {
LOG.debug("Method retry handler returned false. "
+ "Automatic recovery will not be attempted");
throw e;
}
}
}
// ========================================
HttpMethodRetryHandler handler =
(HttpMethodRetryHandler)method.getParams().getParameter(
HttpMethodParams.RETRY_HANDLER);
if (handler == null) {
handler = new DefaultHttpMethodRetryHandler();
}
if (!handler.retryMethod(method, e, execCount)) {
LOG.debug("Method retry handler returned false. "
+ "Automatic recovery will not be attempted");
throw e;
}看异常是handler.retryMethod方法返回false了。估计连接超时了吧。看看你那网站有连接时间限制没。
} catch (HttpException e) {
// filter out protocol exceptions which cannot be recovered from
throw e;
} catch (IOException e) {
LOG.debug("Closing the connection.");
this.conn.close();
http://seanhe.iteye.com/blog/234759