调用httpclient出现[read] I/O error: Read timed out的问题分析和解决办法
2017-12-27 15:19
1041 查看
在使用httpclient 发送http请求时,基本每次都是3秒后,服务器才能收到交易。
日志如下:
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Connection: Keep-Alive[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_144)[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Expect: 100-continue[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "[\r][\n]"
2017-12-25 09:08:26,353 [nioEventLoopGroup-700-1] DEBUG i.n.b.PoolThreadCache - Freed 1 thread-local buffer(s) from thread: nioEventLoopGroup-700-1
2017-12-25 09:08:27,986 [nioEventLoopGroup-701-1] DEBUG i.n.b.PoolThreadCache - Freed 2 thread-local buffer(s) from thread: nioEventLoopGroup-701-1
2017-12-25 09:08:29,005 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 << "[read] I/O error: Read timed out"
=======================================================================================================================
对此,翻看了源码的报错信息,也没有定位到问题的原因。后来还是通过看日志,在报错前有一段“Expect: 100-continue[\r][\n]”,然后翻看了http 1.0和1.1协议,并结合抓包的分析,才恍然大悟。HTTP 1.1支持只发送header信息(不带任何body信息),如果服务器认为客户端有权限请求服务器,则返回100,否则返回401。客户端如果接受到100,才开始把请求body发送到服务器。
之后,只要将http协议改为1.0,就可以瞬间进行发送并收到应答
参考: https://www.ietf.org/rfc/rfc2616.txt
http://blog.csdn.net/kingcodexl/article/details/51306062
http://blog.csdn.net/linsongbin1/article/details/54980801
日志如下:
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Connection: Keep-Alive[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_144)[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Expect: 100-continue[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-12-25 09:08:26,001 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 >> "[\r][\n]"
2017-12-25 09:08:26,353 [nioEventLoopGroup-700-1] DEBUG i.n.b.PoolThreadCache - Freed 1 thread-local buffer(s) from thread: nioEventLoopGroup-700-1
2017-12-25 09:08:27,986 [nioEventLoopGroup-701-1] DEBUG i.n.b.PoolThreadCache - Freed 2 thread-local buffer(s) from thread: nioEventLoopGroup-701-1
2017-12-25 09:08:29,005 [http-nio-8080-exec-8] DEBUG o.a.h.wire - http-outgoing-322 << "[read] I/O error: Read timed out"
=======================================================================================================================
对此,翻看了源码的报错信息,也没有定位到问题的原因。后来还是通过看日志,在报错前有一段“Expect: 100-continue[\r][\n]”,然后翻看了http 1.0和1.1协议,并结合抓包的分析,才恍然大悟。HTTP 1.1支持只发送header信息(不带任何body信息),如果服务器认为客户端有权限请求服务器,则返回100,否则返回401。客户端如果接受到100,才开始把请求body发送到服务器。
之后,只要将http协议改为1.0,就可以瞬间进行发送并收到应答
参考: https://www.ietf.org/rfc/rfc2616.txt
http://blog.csdn.net/kingcodexl/article/details/51306062
http://blog.csdn.net/linsongbin1/article/details/54980801
相关文章推荐
- Axis2调用超时Read timed out的解决办法一则
- Android studio升级3.0 carry2 出现问题Gradle sync failed: Connection timed out: connect解决办法
- jquery1.8版本使用ajax实现微信调用出现的问题分析及解决办法
- angular4 通过httpclient调http接口,出现access-control-allow-origin跨域问题解决办法
- Axis2调用超时Read timed out的解决办法
- Spring Boot使用Feign客户端调用远程服务时出现:timed-out and no fallback available,failed and no fallback available的问题解决
- Maven编译出现“java.lang.OutOfMemoryError: Java heap space”问题及解决办法
- pip 安装包时超时(read timed out)问题解决办法
- Maven编译出现“java.lang.OutOfMemoryError: Java heap space”问题及解决办法
- w7 下配置IIS ,出现的IIS 7.5 HTTP 错误 404.3 - Not Found解决办法及 调用32位动态库问题
- MAVEN2使用mvn install命令出现java.lang.OutOfMemoryError错误解决办法
- Mysql连接时出现Client does not support authentication protocol问题解决办法
- “NETDEV WATCHDOG: eth0: transmit timed out”问题解决办法小结
- Tomcat6下应用太多出现java.lang.OutOfMemoryError: PermGen space【解决办法】
- php5.3开始出现的Function ereg() is deprecated Error问题解决办法
- [原]在Oracle SOASUITE 10g Register ESB 报“The exception reported is: "javax.transaction.RollbackException: Timed out”问题的解决办法
- 在安装Adobe Read9.0时出现了这样的问题,说无法找到AcroRead.msi,解决办法
- mysql4.1版本连接时出现Client does not support authentication protocol问题解决办法
- [总结]Server Application Error(IIS5 HTTP500)内部错误分析及解决办法
- mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法