How to read an http input stream

后端 未结 5 588
孤独总比滥情好
孤独总比滥情好 2020-12-01 07:24

The code pasted below was taken from java docs on HttpURLConnection.

I get the following error:

readStream(in) 

as there is no suc

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 07:57

    try this code

    String data = "";
    InputStream iStream = httpEntity.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(iStream, "utf8"));
    StringBuffer sb = new StringBuffer();
    String line = "";
    
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    
    data = sb.toString();
    System.out.println(data);
    

提交回复
热议问题