httpclient 在获取返回值时,使用getResponseBodyAsString触发警告的问题

使用httpclient通过postmethod对象获取返回值,在使用getResonseBodyAsString方法时会出现一个警告:

 

org.apache.commons.httpclient.HttpMethodBase getResponseBody
警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

 

可以通过如下方式解决:

 

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

你可能感兴趣的:(httpclient)