crawler_httpclient代理访问
1 public String getDocumentByProxy(String url) 2 throws ClientProtocolException, IOException { 3 DefaultHttpClient httpclient = new DefaultHttpClient(); 4 HttpHost proxy = new HttpHost("127.0.0.1", 8087); 5 httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, 6 proxy); 7 HttpGet httpget = new HttpGet(IllegalCharacter(url)); 8 HttpResponse response = httpclient.execute(new HttpGet(url)); 9 String html; 10 try { 11 html = getContent(response, httpget.getURI().getHost()); 12 } finally { 13 httpget.releaseConnection(); 14 // 释放连接 15 httpclient.getConnectionManager().shutdown(); 16 } 17 18 return html; 19 }
create by cphmvp
email:cphmvp@163.com
爬虫技术交流_crawler QQ群 :167047843