解决方案 »

  1.   

    自定义一个方法来代替String s=EntityUtils.toString(response.getEntity()); 这句
    String str = getContent(httpResponse);方法:
    public static String getContent(HttpResponse response) { BufferedReader in = null;
    String page = "";
    try {
    in = new BufferedReader(new InputStreamReader(response.getEntity()
    .getContent()));
    StringBuffer sb = new StringBuffer("");
    String line = "";
    while ((line = in.readLine()) != null) {
    sb.append(line);
    }
    page = sb.toString();
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (in != null)
    try {
    in.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    return page;
    }
    我没遇到过你那样的问题,不过你可以试试这个方法
      

  2.   

    我也遇到了这个问题大概也是String s=EntityUtils.toString(response.getEntity());这就报错,
    试了试楼上的方法不行换成了HttpUrlConnection解决了问题
    public String httpGet2(String url2, String paras) throws Exception { // 拼接url
    if (paras != null && !paras.equals("")) {
    url2 += "?" + paras;
    }
    URL url = new URL(url2);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    conn.setConnectTimeout(5000*4);
    if (conn.getResponseCode() == 200) {
    InputStream is = conn.getInputStream();
    // 将输入流转换成字符串
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = is.read(buffer)) != -1) {
    baos.write(buffer, 0, len);
    }
    String json = baos.toString();
    baos.close();
    is.close();
    //
    return json;
    }
    return "获取数据失败";
    }