1

我像这样在 httpasyncclient 上使用代理:

final CloseableHttpAsyncClient httpclient = HttpAsyncClients
                .createDefault();
httpclient.start();
final HttpGet request = new HttpGet("http://www.apache.org/");
HttpHost proxy = new HttpHost("127.0.0.1", 8888, "http");
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
request.setConfig(config);

final Future<HttpResponse> future = httpclient.execute(request, null);
System.out.println("Response: " + future.get().getStatusLine());

但是请求不通过代理获取数据。为什么?版本:httpasyncclient 4.0-beta4

4

1 回答 1

1

我解决了。

final HttpClientContext localcontext = HttpClientContext.adapt(new BasicHttpContext());
localcontext.setRequestConfig(config);
final Future<HttpResponse> future = httpclient.execute(request, localcontext, null);
于 2013-08-28T23:11:07.590 回答