[英]Cannot get InputStream out of HttpEntity
我有一個從Web服務器收到的HttpEntity。 如果我使用getContentLength()檢查HttpEntity,則顯示值>0。因此似乎存在內容。 我運行getContent()獲得一個InputStream,並在該InputStream上運行read()獲得內容。 在第一個read()操作上,它引發一個IO異常,即關閉流“嘗試在關閉的流上讀取”。
我的代碼是:
HttpEntity myEntity = myResponse.getEntity();
InputStream inputStream = myEntity.getContent();
inputStream.read();
因此,我沒有在該流上調用close()。 我不能排除HttpEntity有問題,在我看到的調試器中查看myEntity(不知道是否有幫助):
is1=EofSensorInputStream
eofWatcher=BasicManagedEntity
selfClosed=true
wrappedStream=null
InputStream上的getContentLength()將值顯示在HttpEntity上。
我不知道從哪里開始尋找問題所在。 我可以檢查什么找到問題?
請參考此鏈接 ,其中說REPEATABLE實體只能使用一次getContent()
和writeTo(OutputStream)
過程。
要知道您的實體是否是REPEATABLE ,請使用isRepeatable()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.