Using getResponseBodyAsStream instead is recommend

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

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



JAVA代码解决方法如下:

HttpMethod method = null;
method = new GetMethod(request.getUrl());
method.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; text/html; charset=UTF-8");


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();  
[本日志由 friend365 于 2017-03-29 04:52 PM 编辑]
文章来自: 本站原创
Tags: 查看次数: 1172