的HttpClient-4.5.2.jar
我的配置如下:
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(maxConnections);
cm.setDefaultMaxPerRoute(maxConnectionsPerRoute);
cm.setMaxPerRoute(new HttpRoute(new HttpHost("https://test.com", 443)), 30);
httpClient= HttpClients.custom().setConnectionManager(cm).build();
HttpResponse response = httpClient.execute(httpPost);
private HttpPost getHttpPost(String url, String param) throws UnsupportedEncodingException {
HttpPost httpPost = new HttpPost(url);
if (!StringUtils.isEmpty(param)) {
StringEntity entity = new StringEntity(param, CHAR_SET_UTF8);
httpPost.setEntity(entity);
}
return httpPost;
}
当httpclient执行httpPost时,它会打印下面的一些日志:
11:46:33.267 [clientInboundChannel-1] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {s}->https://test.com:443
11:46:37.363 [clientInboundChannel-1] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to test.com/{ipAddress}:443
在两个日志之间,它表明打开并连接主机需要4秒。 我不知道我的代码有什么问题。是否由于我没有加载https证书? 有谁知道发生了什么?感谢。