HttpClient get返回String类型 JAVA

    public static String httpGet(String url) {
        // get请求返回结果
        String strResult = "";
        try {
            DefaultHttpClient client = new DefaultHttpClient();
            // 发送get请求
            HttpGet request = new HttpGet(url);
            HttpResponse response = client.execute(request);

            /** 请求发送成功,并得到响应 **/
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                /** 读取服务器返回过来的json字符串数据 **/
                strResult = EntityUtils.toString(response.getEntity());
            }
        } catch (IOException e) {
            System.out.println("get请求提交失败:" + url);
        }
        return strResult;
    }
原文地址:https://www.cnblogs.com/ilazysoft/p/6266943.html