gpt4 book ai didi

proxy - 嗨,我如何配置 Apache HttpClient 以绕过本地地址的代理?

转载 作者:行者123 更新时间:2023-12-04 13:39:44 28 4
gpt4 key购买 nike

我正在像这样配置客户端:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

现在,我想告诉我的客户不要为“localhost”或 127.0.0.1 使用代理。

谢谢!

最佳答案

使用 HttpClient 4.3 API

HttpHost proxy = new HttpHost("someproxy", 8080);
HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy) {

@Override
public HttpRoute determineRoute(
final HttpHost host,
final HttpRequest request,
final HttpContext context) throws HttpException {
String hostname = host.getHostName();
if (hostname.equals("127.0.0.1") || hostname.equalsIgnoreCase("localhost")) {
// Return direct route
return new HttpRoute(host);
}
return super.determineRoute(host, request, context);
}
};
CloseableHttpClient client = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();

关于proxy - 嗨,我如何配置 Apache HttpClient 以绕过本地地址的代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21557602/

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