HttpClient设置代理

更新时间 🔔🕙 2021年5月4日

HttpClient 4的代理设置方法:

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(<proxy-host>, <proxy-port>),
    new UsernamePasswordCredentials(<proxy-username>, <proxy-password>));
httpClient.setCredentialsProvider(credsProvider);
HttpHost proxy = new HttpHost(<proxy-host>, <proxy-port>, "http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);

新版本中已经不使用这种方式,待更新。

转载请备注引用地址:编程记忆 » HttpClient设置代理