通过httpClient4读取页面内容

来源:互联网 发布:淮北网络推广培训学校 编辑:程序博客网 时间:2024/06/06 19:34
http://llying.iteye.com/blog/721511
Java代码  收藏代码
  1. HttpClient httpClient = new DefaultHttpClient();  
  2.         HttpClientParams.setCookiePolicy(httpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY);    
  3.         HttpHost httpHost = new HttpHost("localhost");  
  4.         HttpGet httpGet = new HttpGet("/https/");  
  5.           
  6.         HttpResponse response = httpClient.execute(httpHost,httpGet);  
  7.           
  8.         if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){  
  9.             //请求成功  
  10.             //取得请求内容  
  11.             HttpEntity entity = response.getEntity();  
  12.             //显示内容  
  13.             if (entity != null) {  
  14.                 // 显示结果  
  15.             System.out.println(EntityUtils.toString(entity,"utf-8"));  
  16.             }  
  17.         }  
  18.         httpGet.abort(); 
0 0
原创粉丝点击