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 }