标签:
在使用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
标签:
原文地址:http://www.cnblogs.com/sagech/p/4741755.html