Android与服务器通信常用Http类粗译

来源:互联网 发布:逆袭网络剧第一集哇趣 编辑:程序博客网 时间:2024/06/05 13:21
英文原文:http://developer.android.com/reference/org/apache/http/package-summary.html
org.apache.http
The core interfaces and classes of the HTTP components. These deal with the fundamental things required for using the HTTP protocol, such as representing a message including it's headers and optional entity, and connections over which messages are sent. In order to prepare messages before sending or after receiving, there are interceptors for requests and responses.

http包里有HTTP组件的核心接口和类。这些类在需要使用HTTP协议进行通信的程序里发挥关键作用,比如处理一个包含头和可选实体的消息,以及用来传送消息的连接connection。在消息发送前和接收以后能够准备好消息,提供拦截器用于处理request和response。

——————————————————————————————————————————————————————
public interface

HttpEntity


An entity that can be sent or received with an HTTP message. Entities can be found in some requests and in responses, where they are optional.

In some places, the JavaDoc distinguishes three kinds of entities, depending on where their content originates:

  • streamed: The content is received from a stream, or generated on the fly. In particular, this category includes entities being received from a connectionStreamed entities are generally not repeatable.
  • self-contained: The content is in memory or obtained by means that are independent from a connection or other entity. Self-contained entities are generally repeatable.
  • wrapping: The content is obtained from another entity.
This distinction is important for connection management with incoming entities. For entities that are created by an application and only sent using the HTTP components framework, the difference between streamed and self-contained is of little importance. In that case, it is suggested to consider non-repeatable entities as streamed, and those that are repeatable (without a huge effort) as self-contained.

HttpEntity是使用HTTP消息发送和接收的实体。在request和response中也可以包括实体。

根据实体内容的不同来源可以分为三类:streamed,self-contained,wrapping

管理接收实体时,需要注意三种实体的区别。对于由同一个应用程序创建,并且只使用HTTP组件框架进行发送的实体,这些区别不是特别重要。最好讲不可重复的实体当作streamed,把可重复的实体当作self-contained。

public abstract InputStream getContent ()

Creates a new InputStream object of the entity. It is a programming error to return the same InputStream object more than once. Entities that are not repeatable will throw an exception if this method is called multiple times.

抽象方法getContent()获取实体中的内容,以InputStream字节流的形式返回

public abstract boolean isRepeatable ()

Tells if the entity is capable to produce its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.

可重复的意思是实体能够复制它的数据。在实体是可重复的情况下,getContent和writeTo方法能够被调用超过一次,不可重复实体则不可以。

public abstract void writeTo (OutputStream outstream)

Writes the entity content to the output stream.

把实体内容写到outstream中,以字节流形式读出。
————————————————————————————————————————————————————————
public interface

HttpMessage


A generic HTTP message. Holds what is common between requests and responses.

一般意义上的HTTP消息。它是request和response的公共部分。

———————————————
public interface

HttpResponse

implements HttpMessage

public abstract HttpEntity getEntity ()

Obtains the message entity of this response, if any. The entity is provided by calling setEntity.

获取response中的实体,这个实体由setEntity调用。

——————————————————————————————————————————————————————————————
public interface

HttpClient


Interface for an HTTP client. HTTP clients encapsulate a smorgasbord of objects required to execute HTTP requests while handling cookies, authentication, connection management, and other features. Thread safety of HTTP clients depends on the implementation and configuration of the specific client.

HttpClient是一个client的接口。它封装一系列对象来执行HTTP request,同时能够处理cookies,授权,连接管理和其他功能。Http Client的安全线程依赖于特定client的配置和实施。

——————————————————————————————————————————————————————————————
public class

HttpGet

extends HttpRequestBase

The HTTP GET method is defined in section 9.3 of RFC2616:

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

Get Methods will follow redirect requests from the http server by default. This behaviour can be disabled by calling setFollowRedirects(false).

GET方法用来取回任何有Request-URI标记的实体。如果URI指向一个产生数据的过程,那么应该返回最终产生的数据而不是过程。
各类Get方法会默认从http服务器上响应redirect request。通过调用setFollowRedirects(false)来取消这种操作。

原创粉丝点击