Java httpclient创建https连接花费的时间太长
httpclient-4.5.2.jar 我的配置如下:Java httpclient创建https连接花费的时间太长,java,apache-commons-httpclient,Java,Apache Commons Httpclient,httpclient-4.5.2.jar 我的配置如下: PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(maxConnections); cm.setDefaultMaxPerRoute(maxConnectionsPerRoute); cm.setMaxPerRoute(new HttpRoute(new Htt
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证书吗?
有人知道发生了什么吗?谢谢。您需要使用Wireshark监控网络流量,以确定延迟的位置。在你这么做之前,你不知道在哪里寻找解决方案。可能是服务器需要4秒钟才能响应。一种严重的可能性是服务器对客户端执行rDNS查找,而您没有在网络中配置它,因此它必须等待超时。这可能是一端或两端的DNS延迟,可能是反向DNS查找。在我的示例中,test.com是一个平台,我的服务器可以向我的服务器发送消息,平台可以向我的服务器发送消息,而不仅仅是req rsp。现在,使用http向我的服务器发送消息的平台非常快。但是我的服务器使用httpclient向平台发送https请求的速度太慢了@JimGarrisonwe无法为您执行所需的故障排除。除非你提供必要的信息,否则我们帮不了你。