HttpEntity的containerContent()的用法

编程入门 行业动态 更新时间:2024-10-13 12:17:17
本文介绍了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的建议, HttpEntity.consumeContent() 已弃用,因此请使用 EntityUtils.consume(HttpEntity) (如果可行).

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()的用法

本文发布于:2023-11-25 23:12:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631732.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HttpEntity   containerContent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!