2012-03-19 181 views
0

在我的程序中,我正在調用EntityUtils.consume(httpResponse.getEntity())。這是在代碼中拋出一個IOException,而對EntityUtils.toString(httpResponse.getEntity())的調用完全正常。任何想法可能是什麼問題?或者有什麼建議來解決IOException?EntityUtils .consume返回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);     
     } 
    } 

回答

1

我不熟悉Apache的HttpCore,但我知道Servlet中你不能從HttpServletRequest中讀取兩次日期。它使用緩衝區,一旦緩衝區結束,如果您嘗試讀取兩次,則會發生IOException,因爲緩衝區現在爲空。