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     }

 

posted @ 2014-01-24 17:49  cphmvp  阅读(280)  评论(0编辑  收藏  举报
爬虫在线测试小工具: http://tool.haoshuju.cn/