- //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();
时间: 2024-10-10 01:56:57