HTTP_複習

 public static String getRequest(String url){
        String result  = "";

        //2.創建HttpGet對象
        HttpGet httpGet= new HttpGet(url);
        try {
            //3.發送Get請求
            HttpResponse response = httpClient.execute(httpGet);
            if (response.getStatusLine().getStatusCode() == 200){
                //4.獲取服務器返回的數據
                HttpEntity entity = response.getEntity();
                result  = EntityUtils.toString(entity);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return result ;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章