HTTP explained in detail

Before understanding http, let's understand communication~

communication

concept:

Communication is the transmission and exchange of information.

Three elements of communication:

Who communicates (server and client browser), what to communicate, how to communicate (response)

letter of agreement:

Communication Protocol (Communication Protocol) refers to the rules and agreements that the two parties must abide by to complete the communication.

Popular understanding: The two parties to the communication use the agreed format to send and receive messages. This pre-agreed communication format is called a communication protocol.

Communication protocols in the Internet:

To realize the transmission of webpage content between the client and the server, both parties in communication must abide by the transmission protocol of webpage content.

Web page content is also called hypertext, so the transmission protocol of web page content is also called hypertext transfer protocol, or HTTP protocol for short .

HTTP protocol

concept:

That is, the HyperText Transfer Protocol (HyperText Transfer Protocol), which specifies the transmission format that must be followed when transmitting web page content between the client and the server.

Interaction model:

HTTP uses a request/response interaction model.

HTTP request message

concept:

Since the HTTP protocol belongs to the communication protocol between the client browser and the server. Therefore, the request initiated by the client is called an HTTP request, and the message sent by the client to the server is called an HTTP request message.

Note: HTTP request messages are also called HTTP request packets.

component:

Request line : It consists of three parts: request method, URL, and HTTP protocol version, separated by spaces.

Request header: The request header is used to describe the basic information of the client, so as to inform the server of the relevant information of the client.

Blank line: The last request field is followed by a blank line, informing the server that the request headers are over.

A blank line in the request message is used to separate the request header and the request body.

Request body: The request body stores the data to be submitted to the server through POST.

Note: Only POST requests have a request body, and GET requests have no request body.

HTTP response message

concept:

The response message is the content of the message that the server responds to the client, also called a response message.

component:

Status line: It consists of 3 parts, HTTP protocol version, status code and status code description text, separated by spaces

Response header: The response header is used to describe the basic information of the server. The response header consists of multiple lines of key/value pairs, and the key and value of each line are separated by colons in English.

Blank line: After the end of the last response header field, there will be a blank line immediately to inform the client that the response header is over.

A blank line in the response message is used to separate the response header and response body.

Response body: The response body stores the resource content that the server responds to the client.

HTTP request method

concept:

The HTTP request method is part of the HTTP protocol. The function of the request method is to indicate the operation to be performed on the resources on the server. The most commonly used request methods are GET and POST.

 

HTTP response status code

concept:

The HTTP response status code (HTTP Status Code), also part of the HTTP protocol, is used to identify the status of the response.

The response status code will be sent to the client browser along with the response message, and the browser can know whether the HTTP request is successful or failed based on the response status code returned by the server.

 The HTTP status code consists of three decimal numbers. The first decimal number defines the type of the status code, and the latter two numbers are used to subdivide the status code.

Composition and classification:

 2**Success related response status code

A status code in the range of 2** indicates that the server has successfully received and processed the request.

3** Redirection-related response status codes

The status code in the range of 3** indicates that the server requires the client to redirect, and further operations by the client are required to complete the resource request.

 4**Response status code related to client error

A status code in the range of 4** indicates that the client's request has illegal content, which leads to the failure of this request.

 

5**Response status code related to server error

The status code in the range of 5** indicates an unexpected error caused by the server failing to process the client's request normally.

 

Guess you like

Origin blog.csdn.net/DIUDIUjiang/article/details/126839943