Usage of consumeContent() of HttpEntity

后端 未结 2 1145
你的背包
你的背包 2021-01-21 11:12

What is the purpose of consumeContent() of class or org.apache.http.HttpEntity in Android?

When should one use it ane can it have side effects?

I\'m

2条回答
  •  一整个雨季
    2021-01-21 12:10

    As @Sotirios suggested, HttpEntity.consumeContent() is deprecated so please use EntityUtils.consume(HttpEntity) when feasible.

    Let's then broadly talk about consuming an HttpEntity. Consuming an HttpEntity ensures that all the resources allocated to this entity are deallocated. This means that:

    • The underlying stream is released.
    • If your connection is pooled, your connection object will be given back to the pool. If your connection is not pooled, the connection manager will let go the connection object in question and focus on handling other client requests.

    When should one use it?

    You should free connection resources the moment they are no longer needed. Consuming an HttpEntity does exactly this for you.

    Can it have side effects?

    I am unaware of any side effects of consuming an HttpEntity.

提交回复
热议问题