我无法使用以下代码将Apache 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);
Run Code Online (Sandbox Code Playgroud)
我通过专有API获得连接和端口.当一切顺利时,这有效(但由于我认为连接不良)代码永远挂在client.execute(post).在实现超时或其他方法使我的调用超时时,我在做错了什么,所以我不会无限期地陷入困境.