6
我有麻烦了Apache的HttpClient(4.3)POST请求使用以下代码超时:阿帕奇HttpClient的4.3未超时
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)上。有没有什么我在这里做错了在实现超时或其他方法,使该呼叫有一个超时,所以我不会无限期卡住。
仅供参考(它在4.3.4中似乎已修复):https://issues.apache.org/jira/browse/HTTPCLIENT-1478 – Greg
请注意,它似乎实际上在4.3.4/4.3中进行了修复。 5通过SSL/HTTPS连接时。 – centic
如果您完全阅读HTTPCLIENT-1478,您会看到有几个人抱怨说它实际上没有修复。我正在使用4.4.1,我可以确认此问题仍然存在。 – GaspardP