我在使用以下代码使 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没有这个bug。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)