@Bean
public HttpClient httpClient() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build();
RequestConfig requestConfig = RequestConfig.custom()
//服务器返回数据(response)的时间,超过抛出read timeout
.setSocketTimeout(socketTimeout)
//连接上服务器(握手成功)的时间,超出抛出connect timeout
.setConnectTimeout(connectTimeout)
//从连接池中获取连接的超时时间,超时间未拿到可用连接,会抛出异常
.setConnectionRequestTimeout(connectionRequestTimeout)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
connectionManager.setMaxTotal(maxTotal);
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
return HttpClientBuilder
.create().setDefaultRequestConfig(requestConfig).setConnectionManager(connectionManager).build();
}
httpclient支持https
最新推荐文章于 2024-09-24 23:49:40 发布