Reputation: 698
In my program I am making a call to EntityUtils.consume(httpResponse.getEntity()). This is throwing an IOException in code, whereas a call to EntityUtils.toString(httpResponse.getEntity()) is working perfectly fine. Any ideas on what the issue might be? Or any suggestions to fix the IOException?
if(status >= 200 && status < 300) {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
if(httpEntity.getContentLength() > Constants.HTTP.MAX_APP_CONTENT_LENGTH) {
throw new IllegalArgumentException("HTTP entity too large.");
}
result = EntityUtils.toString(httpEntity,"UTF-8");
EntityUtils.consume(httpEntity);
}
}
Upvotes: 0
Views: 1244
Reputation: 8154
I am not familiar with Apache HttpCore, but I know in Servlets you can't read the date twice from an HttpServletRequest. Its using a buffer, and once the buffer is at the end, if you try to read it twice, you get an IOException because the buffer is now empty.
Upvotes: 1