httpclient 在獲取返回值時,使用getResponseBodyAsString觸發警告

使用httpclient經過postmethod對象獲取返回值,在使用getResonseBodyAsString方法時會出現一個警告:apache

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

能夠經過以下方式解決:post

BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));  spa

StringBuffer stringBuffer = new StringBuffer();  對象

String str = "";  get

while((str = reader.readLine())!=null){  string

   stringBuffer.append(str);  cli

}  httpclient

String ts = stringBuffer.toString();  方法

相關文章
相關標籤/搜索