关于使用httpclient获取返回时报错:Going to buffer response body of large or unknown size

关于使用httpclient请求获取返回时报错:Going to buffer response body of large or unknown size.Using getResponseBodyAsStre

当出现以上警告时使用getResponseBodyAsStream替换getResponseBodyAsString获取返回体信息,可做如下修改:

String html = postMethod.getResponseBodyAsString();

替换为:

BufferedReader reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()));
StringBuffer stringBuffer = new StringBuffer();
String str = "";
while((str = reader.readLine())!=null){
			stringBuffer.append(str);
}
String 	html=stringBuffer.toString();

你可能感兴趣的:(java开发类)