有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用Apache httpclient 4为每个请求设置超时。*使用PoollightTPClientConnectionManager?

如何使用Apache httpclient 4.3和PoolighttpClientConnectionManager,并为每个请求传递ConnectTimeOut和ReadTimeOut

比如, 如果我将CloseableHttpClient设置为Singleton,并使用PoolghttpClientConnection来获取连接,那么对于我发出的每个请求,我都希望根据目标主机发送不同的超时值

例如,主机A 10秒,主机B 5秒等

请告知


共 (1) 个答案

  1. # 1 楼答案

    HttpGet get1 = new HttpGet("http://hosta/");
    RequestConfig config1 = RequestConfig.custom().setSocketTimeout(10000).build();
    get1.setConfig(config1);
    HttpGet get2 = new HttpGet("http://hostb/");
    RequestConfig config2 = RequestConfig.custom().setSocketTimeout(5000).build();
    get2.setConfig(config2);