Java apache httpclient 4.3未超时

Java apache httpclient 4.3未超时,java,timeout,apache-httpclient-4.x,connection-timeout,Java,Timeout,Apache Httpclient 4.x,Connection Timeout,我无法使用以下代码使Apache HttpClient(4.3)post请求超时: RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(4000).setConnectTimeout(4000) .setSocketTimeout(4000).build(); CloseableHttpClient client = HttpClients.custom().setSs

我无法使用以下代码使Apache HttpClient(4.3)post请求超时:

RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(4000).setConnectTimeout(4000)
        .setSocketTimeout(4000).build();

CloseableHttpClient client = HttpClients.custom().setSslcontext(sslContext)
        .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
        .setDefaultRequestConfig(requestConfig).build();

HttpPost post = new HttpPost("https://localhost:" + connection.getLocalPort() + "/API/webservice.asmx");

StringEntity stringE = new StringEntity(REQUEST);
    post.setEntity(stringE);

CloseableHttpResponse response = client.execute(post);

我通过专有API获得连接和端口。当一切顺利时,这种方法有时会工作(我相信是由于连接不好),代码永远挂在client.execute(post)上。在实现超时或其他方法使调用超时时,是否有什么地方我做错了,这样我就不会无限期地陷入困境。

这是HttpClient 4.3中https连接的一个错误。在尝试SSL握手之前,未在套接字上设置套接字超时。在握手过程中,线程可能挂起等待套接字读取。HttpClient 4.2没有此错误

供参考(在4.3.4中似乎是固定的):请注意,通过SSL/HTTPS连接时,它在4.3.4/4.3.5中似乎实际上是固定的。如果您完全阅读了HTTPCLIENT-1478,您将看到有几个人抱怨它实际上没有固定。我正在使用4.4.1,我可以确认此问题仍然存在。@GaspardPetit您是对的。我正在HTTPS上使用HttpClient 4.3.5。我已经将连接超时设置为1分钟,并且连接在15分钟后也不会关闭。我刚刚用HttpClient 4.5.2测试了这一点,现在它肯定已经修复了。确保设置套接字配置:
poolghttpclientconnectionmanager connManager=new-poolghttpclientconnectionmanager();connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(35000.build())