有時(shí)候由于不可抗力,我們爬外面的東西的時(shí)候需要設(shè)置代理份招,設(shè)置方法如下:
Jsoup
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
Connection connection = Jsoup.connect(url).proxy(proxy);
HttpClient4.3
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet get = new HttpGet(moreUrl);
HttpHost proxy = new HttpHost("localhost", 1080);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
get.setConfig(config);
CloseableHttpResponse response = httpclient.execute(get);