Programming > Java

Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

경고: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

9월 10, 2017 1:26:12 오후 org.apache.commons.httpclient.HttpMethodBase getResponseBody
경고: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

 

before

postMethod = new PostMethodUTF8(url);
postMethod.setRequestBody(data);
int responseCode = httpClient.executeMethod(postMethod);
if(responseCode!=200){
    rmap.put("result", "NG");
    rmap.put("code", String.valueOf(responseCode));
    rmap.put("msg", "responseCode is " + responseCode);
    return rmap;
}
responseBody = postMethod.getResponseBodyAsString();
ObjectMapper mapper = new ObjectMapper();
rmap = mapper.readValue(responseBody, Map.class);

 

after

postMethod = new PostMethodUTF8(url);
postMethod.setRequestBody(data);
int responseCode = httpClient.executeMethod(postMethod);
if(responseCode!=200){
    rmap.put("result", "NG");
    rmap.put("code", String.valueOf(responseCode));
    rmap.put("msg", "responseCode is " + responseCode);
    return rmap;
}
InputStream is = postMethod.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));

StringBuilder sb = new StringBuilder();
String line;
while((line=br.readLine()) != null) {
    sb.append(line);
}
br.close();


ObjectMapper mapper = new ObjectMapper();
rmap = mapper.readValue(sb.toString(), Map.class);