u011359326
提问之星
2016-02-25 09:41
采纳率: 99.8%
浏览 1.5k
已采纳

java中HttpGet和HttpClient和HttpResponse之间的联系是如何的

java中HttpGet和HttpClient和HttpResponse之间的联系是如何的
每一个对象分别承载着什么信息

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • Mr_dsw
    Antway_ 2016-02-25 09:48
    已采纳
     public class HTTPGetSample {  
        public static void main(String[] args) throws ClientProtocolException, IOException {  
            String url = "http://www.google.com.hk/search?q=httpClient";  
    
            HttpClient client = new DefaultHttpClient();  
            HttpGet request = new HttpGet(url);  
    
            HttpResponse response = client.execute(request);  
            System.out.println("Response Code: " +  
            response.getStatusLine().getStatusCode());  
    
            BufferedReader rd = new BufferedReader(  
                new InputStreamReader(response.getEntity().getContent()));  
            String line = "";  
            while((line = rd.readLine()) != null) {  
            System.out.println(line);  
            }  
        }  
    } 
    

    在这个例子中可以看出,HttpGet是我们请求的类型,为GET请求,然后通过HttpClient执行HttpGet请求,返回HttpResponse

    点赞 评论

相关推荐