Apache HttpComponents HttpClient 超时
如何在httpcomponents httpclient中设置连接超时?我在以下位置找到了文档: http://hc.apache。 org/httpcomponents-client-ga/tutorial/html/connmgmt.html 但尚不清楚这些参数的实际设置方式。
此外,解释 SO_TIMEOUT
和 CONNECTION_TIMEOUT
之间的差异也会有所帮助。
How do I set the connection timeout in httpcomponents httpclient? I have found the documentation at: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html but it is not clear how these parameters are actually set.
Also, an explanation of the difference between SO_TIMEOUT
and CONNECTION_TIMEOUT
would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Apache Http Client 4.3 版本中,配置被重构(再次)。新的方式看起来像这样:
In version 4.3 of Apache Http Client the configuration was refactored (again). The new way looks like this:
在 HttpClient 4.3 版本中,您可以使用下面的示例..假设 5 秒
In HttpClient 4.3 version you can use below example.. let say for 5 seconds
@jontro 的答案是正确的,但有一个关于如何执行此操作的代码片段总是很好。有两种方法可以执行此操作:
版本 1:为每个参数设置 10 秒超时:
版本 2:还为以下每个参数设置 10 秒超时:
The answer from @jontro is correct, but it's always nice to have a code snippet on how to do this. There are two ways to do this:
Version 1: Set a 10 second timeout for each of these parameters:
Version 2: Also set a 10 second timeout for each of these parameters:
在第 2.5 节中,您会看到一个示例,说明如何设置 CONNECTION_TIMEOUT 参数。
CONNECTION_TIMEOUT 是等待初始连接的时间,SO_TIMEOUT 是连接建立后读取数据包时等待的超时时间。
In section 2.5 you see an example of how to set the CONNECTION_TIMEOUT parameter.
CONNECTION_TIMEOUT is the time waiting for the initial connection and SO_TIMEOUT is the timeout that you wait for when reading a packet after the connection is established.
我为整个请求设置了硬超时,以解决 java.net.SocketInputStream.socketRead0 问题。
I set a hard timeout for the entire request to workaround the
java.net.SocketInputStream.socketRead0
problem.