小编Gre*_*reg的帖子

apache httpclient 4.3没有超时

我无法使用以下代码将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).在实现超时或其他方法使我的调用超时时,我在做错了什么,所以我不会无限期地陷入困境.

java timeout connection-timeout apache-httpclient-4.x

6
推荐指数
1
解决办法
4792
查看次数