crawler_httpclient代理访问

时间:2021-07-19 20:08:10
 public String getDocumentByProxy(String url)
throws ClientProtocolException, IOException {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("127.0.0.1", 8087);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
HttpGet httpget = new HttpGet(IllegalCharacter(url));
HttpResponse response = httpclient.execute(new HttpGet(url));
String html;
try {
html = getContent(response, httpget.getURI().getHost());
} finally {
httpget.releaseConnection();
// 释放连接
httpclient.getConnectionManager().shutdown();
} return html;
}