关于HttpClient 出现 The target server failed to respond异常的解决办法.
问题描述:使用 HttpClient访问web服务器提供的 接口 如:192.168.1.1/hello 偶尔出现 The target server failed to respond 问题.
通过百度得知,这个错误大致是说server给的不是正确的http response.这个错误是可能是由于:使用同一个HttpClient长连接/保持连接, 然后又使用这个httpClient进行其他网络请求。
通过该提示,想到了两种解决办法,
1.每次要使用一次连接都 通过 工厂 new 一个新的HttpClient 。
2.通过 HttpClient 得到 ClientConnectionManager 类,(getHttpClient().getConnectionManager())使用closeExpiredConnections();方法关闭过期连接.
两种方法皆成功。
第一种比较消耗内存!
相关推荐
JAVAHttpClientThe server failed to respond with a validCaused by: org.apache.htt
用VC实现http协议,构造httpserver和httpclient两端应用实例。
使用mongoose实现了httpserver,httpclient,websocketserver
轻量级C++实现的httpserver和httpclient,给予mongoose,代码量很小,可以方便嵌入到自己的项目中,为C++项目添加http的功能,抛弃libcurl这种重型库
赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...
http工具类,用户java后台请求其他接口,有post请求方式,get请求方式,正常情况下String JSON_CONTENT_TYPE="application/json; encoding=utf-8";
帮助程序员快速从Apache的HttpClient 3.x升级到HttpClient 4.x
Web services, network-enabled appliances and the growth of network computing continue to expand the role of the HTTP protocol beyond user-driven web browsers, while increasing the number of ...
全网唯一的基于java 写的完整的httpservlet 实现,可通过xml 灵活配置
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....
httpclient
完全兼容jdk1.7,1.8,完整包含所有依赖包...* [HTTPCLIENT-1788] RFC 6265 policy must not reject cookies with paths that are no prefix of the uri path. Contributed by Oleg Kalnichevski <olegk at apache.org>
HttpClient seeks to fill this void by providing an efficient, up-to-date, and feature-rich package implementing the client side of the most recent HTTP standards and recommendations. Designed for ...
Web services, network-enabled appliances and the growth of network computing continue to expand the role of the HTTP protocol beyond user-driven web browsers, while increasing the number of ...
httpClient完整封装获取网页信息、数据的代码+httpclient.jar
HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...
httpclient-4.5所需jar包,里面包含httpclient-4.5.jar等等10个必须的开发包。 1.commons-codec-1.9.jar 2.commons-logging-1.2.jar 3.fluent-hc-4.5.jar 4.httpclient-4.5.jar 5.httpclient-cache-4.5.jar 6....
httpclient jar包 httpclient jar包 httpclient jar包
httpclient.jar下载 包括code.jar包