HttpComponent 客户端的默认超时

2022-09-01 21:45:15

我找不到有关 httpclient 4.1 的默认 httpParams 的任何文档?

执行 GET 时的默认套接字超时是什么?


答案 1

根据文档,该参数控制SO_TIMEOUT值,并且:http.socket.timeout

如果未设置此参数,则读取操作将不会超时(无限超时)。


答案 2

接受的答案不适用于较新版本的 HttpClient。版本4.3.X及更高版本使用系统默认值,通常为60秒。

取自HttpClient javadoc。

public int getSocketTimeout()
Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets).
A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default).

Default: -1

推荐