HTTP information in the--HTTP message in the schematic HTTP note (Chapter III)

Source: Internet
Author: User
Tags character set

HTTP Messages

The information used for HTTP laundry interaction is called an HTTP message. The request side (client) HTTP message is called the request message, the response end (server side) called the response message. The HTTP message itself is a string literal consisting of multirow (with Cr+lf as a newline character) data.

The HTTP message can be roughly divided into two pieces: header and message body. The two are divided by the initial empty line (CR+LF), and the message body is not required.



structure of Request message and response message




The header of the request message and the response message consists of the following data:

Request Line:

Contains the method used for the request, the request URI, and the HTTP version

Status line:

Contains status codes, reason phrases, and HTTP versions that indicate the result of the response.

Header field:

Contains the various headers that represent the various conditions and attributes of the request and response. There are generally 4 types of headers, namely: General header, request header, response header, and entity header.

Other: Undefined header (cookie, etc.) in RFC that may contain HTTP


encoding increases transfer rate

HTTP can transmit data in a direct way, but it can also improve transmission efficiency by encoding during transmission. The encoded operation requires a computer to complete, which consumes more resources, such as CPU, at a time.

Difference between the message body and the entity body:

Message (message)

is the basic unit of HTTP communication, consisting of 8-bit byte streams, which are transmitted over HTTP traffic.

Entities (Entity)

The payload data is transmitted as a request or response, and its contents consist of the entity header and the entity body.

Usually the message body equals the entity body. The content of the entity body is changed only when it is encoded in the transmission, which causes it to differ from the message body.

There is a feature called content encoding in the HTTP protocol that can compress the content encoding of the transmission. The content encoding indicates the encoding format applied to the entity content and keeps the entity information compressed as it is. The content-encoded entity is received by the client and is responsible for decoding.

Commonly used content encoding has the following types:

Gzip (GUN Zip)

Compress (standard compression of UNIX systems)

Deflate (zlib)

Identify (not coded)

Chunked transfer code for split send

In the HHTP communication process, the requested encoding entity resource has not yet been fully transmitted before the browser cannot say the request page is displayed. When transferring large volumes of data, the data is segmented into chunks, allowing the browser to progressively display the page. chunked transfer encoding divides the entity body into multiple partial blocks. Each block is marked with hexadecimal, and the last piece of the entity body is marked with "0 (CR+LF)". The client is responsible for decoding and reverting to the entity body before encoding.


multi-Part object collection for sending multiple data

There is a collection of multipart objects in the HTTP protocol, which can contain multiple types of entities within the body of a message being sent. This is usually used when uploading a picture or text file. The multi-part object collection contains the following objects:

Multipart/form-data is used when uploading Web Forms files.

The Multipart/byteranges Status Code 206 (partial content, partial contents) is used when the response message contains multiple ranges of content.



When using a multipart object collection in an HTTP message, you need to add Content-type to the header field. The boundary string is divided into the various entities specified by the multi-part object collection. Inserts the "---" tag (column such as:--aab03x) before the starting line of each entity specified by the boundary string, and ends with the last insert "--" tag (for example:--aab03x--) of the string corresponding to the multipart object collection. Each part type of a multipart object collection can contain a header field. In addition, you can nest a collection of multi-part objects in a section.


get scope requests for partial content

You can resume the download from the previous download outage, and you need to specify the range of entities to download to implement this feature. Like this, a request sent by a specified range is called a range request. For a 10000-byte resource, if you use a range request, you can request only resources within the 5001~10000 byte.




For a range request, the response returns a status code of 206. For multi-range range requests, the response returns a response message after the header field Content-type indicates multipart/byteranges. If the server side cannot respond to a range request, a status code of OK and full entity content is returned.

content Negotiation Returns the most appropriate content

When the browser's default language is English or Chinese, a Web page with the same URI will be displayed in the English or Chinese version. Such a mechanism is called content negotiation (negotiation).

The content negotiation mechanism refers to the client and server to negotiate the content of the response, and then provides the most appropriate resources for the client. Content negotiation responds to the resource's language, character set, encoding, and so on as a benchmark for judgment.

Some of the header fields contained in the request message are the baseline of the judgment: Accept,accept-charset,accept-encoding,accept-language,content-language.

There are 3 types of content Negotiation technologies: Server-driven negotiation, client-driven negotiation, transparent negotiation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.