HTTP protocol explanation [transfer]

Source: Internet
Author: User

HTTP is an application layer protocol consisting of requests and responses. It is a standard client server model. HTTP is a stateless protocol.

The HTTP (port 80) protocol is usually carried over the TCP protocol, and sometimes over the TLS or SSL protocol layer. At this time, it becomes what we often call HTTPS (port 443 ).

The HTTP protocol always initiates a request from the client, and the server returns the response. This restricts the use of the HTTP protocol and prevents the server from pushing messages to the client when the client does not initiate a request. HTTP is a stateless protocol. This request on the same client does not correspond to the previous request.

An HTTP operation is called a transaction. The procedure can be divided into four steps:

1) First, the client and the server need to establish a connection. Click a hyperlink to start HTTP.

2) After a connection is established, the client sends a request to the server in the format of Uniform Resource Identifier (URL), Protocol version number, the mime information is followed by the request modifier, client information, and possible content.

3) after receiving the request, the server returns the corresponding response information in the format of a status line, including the Protocol version number of the information, a successful or wrong code, mime information is followed by server information, entity information, and possible content.

4) The information returned by the client receiving server is displayed on the user's display screen through a browser, and the client is disconnected from the server.

If an error occurs in one of the preceding steps, the error message is returned to the client and displayed. For users, these processes are completed by HTTP. Users only need to click and wait for the information to be displayed.

HTTP Request Message format:

The HTTP Request Message consists of four parts: request line, request header, blank line, and request body.

1. The request line consists of three parts: Request Method, Uri (common resource identifier, note that this is not a URL), and Protocol version, separated by Spaces

Request methods include get and post. Common protocol versions include HTTP/1.1.

2. The request header contains many useful information about the client environment and request body.

The request header is composed of "key/value" pairs. Each line has one pair. keywords and values are separated ":".

3. Empty line. This line is very important and is indispensable. It indicates that the request header ends and the request body is followed.

4. Request body, such as form data submitted in post Mode

GET request example:

POST request example:

What is the difference between the GET request method and the post request method:

1. The post method is safer (relative) than the get method)

The GET request parameters are placed in the request line as part of the request URI, and the post request parameters are placed in the Request body. We can encrypt the Request body.

2. If a large amount of data is transmitted, the POST method can only be used.

Because the get method places the Request Parameters in the request row Uri, the length of the parameter is limited by the length of the URL; the POST request parameters are placed in the Request body, and the request body has no length limit.

HTTP Response Message format:
The HTTP Response Message consists of the Status line, Response Header, blank line, and response body.

1. The status line consists of three parts: HTTP Protocol version, status code, and status code description.

The status code is a three-digit number that starts with 1, 2, 3, 4, and 5. the status code starts with 2 indicates that the response is successful, the status code starts with 3 indicates redirection, And the status code starts with 4 indicates a client error, A server error starts with 5. The detailed status code is not described. Here are several common ones:

200: Response successful

400: the HTTP request sent by the user is incorrect.

404: the file does not exist, that is, the HTTP request URI is incorrect.

500: Internal Server Error

2. The response header is similar to the request header and contains a lot of useful information.

3. Empty rows. This line is very important and is indispensable. It indicates that the response header is over and the response body is followed.

4. response body. The most common document returned by the server is the HTML webpage.

Response example:

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.