我找不到关于 httpclient 4.1 的默认 httpParams 的任何文档?
当我执行 GET 时,默认的套接字超时是多少?
根据文档,该http.socket.timeout
参数控制 SO_TIMEOUT 值,并且:
如果未设置此参数,则读取操作不会超时(无限超时)。
接受的答案不适用于较新版本的 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
对于 Apache HttpClient 版本 4.x 以上
int timeout = 5*60; // seconds (5 minutes)
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000).build();
HttpClient httpClient =
HttpClientBuilder.create().setDefaultRequestConfig(config).build();
我正在观察无限超时。我正在使用 httpclient 4.5.13,而后者又使用 httpcore 4.4.13,其中 SocketConfig 类定义了默认值 0(无超时)。https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/config/SocketConfig.html#getSoTimeout()
超时值为零被解释为无限超时。负值被解释为未定义(系统默认值)。
默认值:-1