HTTP message format

Source: Internet
Author: User
Zookeeper

HTTP packets are text-oriented. Each field in the packet is an ASCII string, and the length of each field is uncertain. HTTP has two types of packets: Request Message and Response Message.

Request Message

An HTTP Request Message consists of four parts: request line, request header, empty line, and request data. The following figure shows the general format of the request message.

(1) Request Line

A request line consists of three fields: Request Method Field, URL field, and HTTP Protocol version field, which are separated by spaces. For example, get/index.html HTTP/1.1.

HTTP request methods include get, post, head, put, delete, options, trace, and connect. The most common get and post methods are described here.

Get: when the client wants to read documents from the server, use the get method. The get method requires the server to place the URL-located resource in the data part of the Response Message and send it back to the client. When the get method is used, the request parameters and corresponding values are appended to the URL, and a question mark ("?") is used. It indicates the end of the URL and the start of the request parameter. The length of the transfer parameter is limited. For example,/index. jsp? Id = 100 & OP = bind.

Post: the post method can be used when the client provides more information to the server. The post method encapsulates Request Parameters in the HTTP request data in the form of Names/values, and can transmit a large amount of data.

(2) Request Header

The request header consists of a pair of keywords and values. Each line is a pair. The keywords and values are separated by a colon. The request header notifies the server of client request information. Typical request headers include:

User-Agent: browser type of the request.

Accept: List of content types that can be recognized by the client.

HOST: the requested host name, which allows multiple domain names to share one IP address, that is, the virtual host.

(3) Empty rows

The last request header is followed by an empty line that sends a carriage return and line feed, notifying the server that there are no request headers below.

(4) request data

The request data is not used in the get method, but in the POST method. The post method is applicable when the customer needs to fill out the form. The most frequently used request headers related to request data are Content-Type and Content-Length.

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.