gpt4 book ai didi

java - 为什么代理不在 httpasyncclient 上使用

转载 作者:太空宇宙 更新时间:2023-11-04 07:26:16 26 4
gpt4 key购买 nike

我在 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

最佳答案

我解决了。

final HttpClientContext localcontext = HttpClientContext.adapt(new BasicHttpContext());
localcontext.setRequestConfig(config);
final Future<HttpResponse> future = httpclient.execute(request, localcontext, null);

关于java - 为什么代理不在 httpasyncclient 上使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18480718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com