HttpClient 和连接超时
HttpClient and Connection Timeout
我通过 Apache HttpClient 发送 http 请求,我的代码在这里:
HttpHost proxy = new HttpHost("78.1.1.222", 80);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Authorization","Basic " + encoding);
httpGet.addHeader("Cache-Control", "no-cache");
httpResponse = httpClient.execute(httpGet);
responseCode=httpResponse.getStatusLine().getStatusCode();
........
........(code continue..)
我的问题是如何向这段代码添加连接超时时间?
请注意,我必须使用代理,我使用 HttpClient 4.4 。
http://www.baeldung.com/httpclient-timeout 解释了设置连接超时的各种方法。
我通过 Apache HttpClient 发送 http 请求,我的代码在这里:
HttpHost proxy = new HttpHost("78.1.1.222", 80);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
httpClient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Authorization","Basic " + encoding);
httpGet.addHeader("Cache-Control", "no-cache");
httpResponse = httpClient.execute(httpGet);
responseCode=httpResponse.getStatusLine().getStatusCode();
........
........(code continue..)
我的问题是如何向这段代码添加连接超时时间? 请注意,我必须使用代理,我使用 HttpClient 4.4 。
http://www.baeldung.com/httpclient-timeout 解释了设置连接超时的各种方法。