HttpEntity的containerContent()的用法 [英] Usage of consumeContent() of HttpEntity

查看:143
本文介绍了HttpEntity的containerContent()的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

consumeContent() org.apache.http.HttpEntity 在Android中?

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?

我正在尝试修复应用程序中的一个错误,该错误使用HttpClient向服务器发出请求,有时即使一个特定的请求失败,尽管互联网正常,但随后也会失败.应用在输入流读取结束时调用此方法.

I'm trying to fix a bug in an app which makes requests to a server using HttpClient and sometimes if one particular request fails it will subsequently fail despite the fact that internet is OK. The app calls this method at the end of input stream read.

推荐答案

按照@Sotirios的建议,

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

接下来,我们将广泛讨论使用HttpEntity的问题.消耗HttpEntity可确保释放分配给该实体的所有资源.这意味着:

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:

  • 基础流已释放.
  • 如果连接已池化,则连接对象将被返回给池.如果您的连接未建立池,则连接管理器将放开有问题的连接对象,并专注于处理其他客户端请求.

何时应该使用它?

When should one use it?

您应该在不再需要连接资源时释放它们.食用HttpEntity完全可以满足您的需求.

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?

我不知道食用HttpEntity有什么副作用.

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

这篇关于HttpEntity的containerContent()的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆