HttpClient本身是一个HTTP通信协议的实现,所以也是支持使用代理访问目标地址的。

maven:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.4</version>
</dependency>
   HttpHost proxy = new HttpHost(proxyIp,proxPport);
   DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
   CloseableHttpClient httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build();

代理 IP http://www.kuaidaili.com/free/intr/
测试接口 http://pv.sohu.com/cityjson?ie=utf-8

标签: HttpClient

添加新评论