码迷,mamicode.com
首页 > 数据库 > 详细

httpClient使用中报错org.apache.commons.httpclient.HttpMethodBase - Going to buffer response body of large or unknown size.

时间:2015-08-19 13:01:29      阅读:3814      评论:0      收藏:0      [点我收藏+]

标签:

在使用HttpClient发送请求,使用httpMethod.getResponseBodyAsString();时当返回值过大时会报错:

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

可以如下解决:

 

1 BufferedReader reader = new BufferedReader(new InputStreamReader(httpMethod.getResponseBodyAsStream()));  
2                 StringBuffer stringBuffer = new StringBuffer();  
3                 String str = "";  
4                 while((str = reader.readLine())!=null){  
5                     stringBuffer.append(str);  
6                 }  
7                 String ts = stringBuffer.toString(); 

得到相应的字符串。

 

ps:

org.apache.commons.httpclient.HttpClient

httpClient使用中报错org.apache.commons.httpclient.HttpMethodBase - Going to buffer response body of large or unknown size.

标签:

原文地址:http://www.cnblogs.com/sagech/p/4741755.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!