thi*_*one 14 java apache-httpcomponents
我在httpclient 4.1的默认httpParams上找不到任何文档?
我做GET时默认的套接字超时是多少?
Cha*_*dru 13
接受的答案不适用于较新版本的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
Run Code Online (Sandbox Code Playgroud)
对于 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();
Run Code Online (Sandbox Code Playgroud)