HTTP protocol Detailed

Source: Internet
Author: User

HTTP--hyper text Transfer Protocol, Hypertext Transfer Protocol, is a stateless connection based on TCP, the entire basic workflow is that the client sends an HTTP request stating the resources the client wants to access and the requested action, after the server receives the request , the server makes the corresponding action and returns the resource to the client through the HTTP response .

Directory

    • HTTP request

    • HTTP response

    • HTTP message Format

    • HTTP protocol version replacement

    • Number of website visits

First, http request

An HTTP request is a client sending a request action to the server, informing it of its own requirements.

The HTTP request consists of the status line , the request header , and the request body :

Status line: Includes the request method, the resource path URL, and the protocol version versions;

Request header: Including some access to the domain name, user agents, cookies and other information;

Request body: Is the data of the HTTP request.

Note: The request method generally has get, POST, PUT, delete, meaning is to get, modify, upload, delete, where Get method is only to obtain server resources, the way is relatively simple, so in the request method is get HTTP request data, the request body part can be omitted , add the resources you want to get directly to the URL. Shown is a GET request, no request body. The detailed instructions are below.

Most protocol versions are now http/1.1

As shown in the format of the POST request, there are status lines, request headers, request body three parts.

Second, HTTP response

2.1 Response data format

After the server receives the HTTP request from the client, the service side makes a specific action according to the action request in the HTTP request, which responds to the client, called the HTTP response.

The HTTP response consists of three parts: a status line, a response header, and a response body ;

Status line: Includes version of Protocol, status code, and response phrase;

Response header: Including software to build the server, send response time, response data format and other information;

Response body: Is the specific data of the response.

Note: We are mainly concerned about and can see in the client browser is a three-digit status code , different status code represents a different meaning, where

1xx Indicates that the HTTP request has been accepted and continues processing the request
2xx Indicates that the HTTP request has been processed for completion
3xx Redirects the URL of the requested access to a different directory
4xx Indicates an error occurred on the client
5xx Indicates an error occurred on the server side

The specific HTTP response is real for example:

2.2 Meaning of common status codes

---ok/request has been processed properly

301---/request permanent redirect

302---/Request temporary redirection

304---/Request redirected to client local cache

---/client request has a syntax error

401---/client request not authorized

403---/client requests are rejected by the server and generally do not have access rights to the client

404---/client-requested URL does not exist on the server

---/service-side permanent error

503---/server temporary error occurred

Third, HTTP message format

HTTP messages are data blocks transmitted between HTTP applications, and HTTP messages are divided into HTTP request messages and HTTP response messages, but no matter what kind of message, his overall format is similar, roughly from the beginning, the first, the main three parts, starting to explain the action of the message, the first description of the properties of the message, The subject is the data of the message. Next, specify.

3.1 HTTP request message

The start of the request message is made up of the request line (some data is called the status line, the name is different, all refers to a thing), to describe what the request to do, consists of <Method>, <URL>, <Version> three fields, Note there is a space between each field.

Where the <Method> field has different values:

GET---Access to the server's resources

Post---Send data to the server to be modified

HEAD---Get the header of the server document

PUT---Upload resources to the server

Delete---Remove resources from the server

The <URL> field indicates the resource directory location of the server

The <Version> field indicates the version of the HTTP protocol used

The first part consists of a number of request headers (also called the header row), and those header field names are below, not all:

Accept specifies the types of content formats that clients can receive

ACCEPT-LANGUAGE Specifies the language type that the client can accept

accept-ecoding Specifies the type of encoding that the client can accept

User-agent User agent, describe your operating system, browser and other information to the server

Connection whether to turn on persistent connection (keepalive)

Host Server domain Name

...

The main part is the specific data of the message.                       

3.2 HTTP response Messages

The start of the response message is made up of the status line to indicate what the server has done, consisting of <Version>, <Status-Code>, <Phrase> three fields, with spaces between each field;

<Status-Code> above has been explained;

The header consists of multiple response headers (also called header lines), with the first field name below, not full:

Server server Software name, Apache/nginx

Date when the server sent a response message

Last-modified The last modification time of the requested resource

...

The main part is the specific data of the response message.

tips: For more request headers and response headers (that is, the header field name), refer to Http://tools.jb51.net/table/http_header    

Four, HTTP protocol version replacement

http/0.9

The initial version of the HTTP protocol, which is rudimentary, only supports request-mode get, and can only request access to resources in HTML format .

http/1.0

Progress was made in version 0.9, with the addition of the request mode post and head, no longer limited to the 0.9 version of the HTML format, according to Content-type can support a variety of data formats, namely MIME Multi-purpose Internet Mail extension , For example, text/html, Image/jpeg, etc., also started to support the cache, that is, when the client access to the unified website within a specified time, direct access to the cache .

However, the 1.0 version works by sending only one request per TCP connection, which closes the connection when the server responds, and the next request needs to establish a TCP connection again, that is, keepalive is not supported.

http/1.1

Resolves the 1.0 version of the keepalive issue, the 1.1 version joined the persistent connection, a TCP connection can allow multiple HTTP requests , joined the pipeline mechanism, a TCP connection allows simultaneous simultaneous transmission of multiple requests , increasing concurrency; added request way put, PATCH, DELETE and so on.

However, there are still some problems, the server is processing the request in queue order, if a request processing time is very long, it will cause the back of the request can not be processed, which caused the team head blocking problem, and HTTP is a stateless connection, so each request will need to add duplicate fields , which reduces the utilization of bandwidth.

http/2.0

In order to solve the problem of low utilization of version 1.1, the http/2.0 version was proposed. Increase the duplex mode , that is, not only the client can send multiple requests simultaneously, the server can also handle multiple requests at the same time, solve the problem of team head congestion; in HTTP requests and responses, the status line and the request/response header are information fields, and there is no real data. Therefore, in version 2.0, all information fields are created with a table that indexes each field in the table, and the client and server use the table together to represent the information field by index number , thus avoiding the repetition of the 1.0 old version of the field and Compressed way of transmission , improve utilization.

In addition, it also increases the function of server push , that is, to send the data to the client actively without the request service side.

The current mainstream protocol version is still the http/1.1 version.

Five, number of website visits

IP IP Access Volume

The same public IP is calculated once, that is, all users in the same LAN access a website, but they are using a public network IP to access the site (NAT), so this can only be counted as an IP traffic. Changing the public IP will add 1.

PV Web page traffic

User access to the number of pages is PV access, the same local area network of different users, and even if the same user, just refresh the site page, PV access is added 1, three traffic value is often the number of PV value maximum.

Number of UV visitor visits

Visitors here are not users, but computers, a computer to count a visitor, even if the same computer different users, access to the same site UV can only add 1, only the replacement of the computer will make UV plus 1, because the server will record the client computer information.


HTTP protocol Detailed

Related Article

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.