标签:httpclient
//private static HttpClient httpClient = HttpClientBuilder.create().build();
private static CloseableHttpClient httpClient;// = HttpClientBuilder.create().build(); //no timeout handling...
static {
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
//客户端和服务器建立连接的timeout
requestConfigBuilder.setConnectTimeout(30000);
//从连接池获取连接的timeout
requestConfigBuilder.setConnectionRequestTimeout(30000);
//连接建立后,request没有回应的timeout
requestConfigBuilder.setSocketTimeout(30000);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
clientBuilder.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(30000).build()); //连接建立后,request没有回应的timeout
clientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());
httpClient = clientBuilder.build();
标签:httpclient
原文地址:http://61455626.blog.51cto.com/1360190/1957827