提问之星 2016-02-25 09:41 采纳率: 90%
浏览 1509
已采纳

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

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

  • 写回答

1条回答

  • Exploring1024 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable