调用httpclient出现[read] I/O error: Read timed out的问题分析和解决办法

在使用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


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值