HTTP protocol [enhanced] [detailed]

HTTP protocol enhancement

Let's talk about what is the http protocol, the components of the http request message, and the components of the corresponding message; finally understand the common request methods and common response status codes.

What is Communication in the Internet

It is 服务器to send the content of the communication through the response 客户端浏览器;

in:

  1. The main body of the communication is: the server and the client browser
  2. The content of the communication is: the data transmitted
  3. The way of communication is: Response

What is the communication protocol in the Internet

To realize the transmission of webpage content between the client and the server, both parties must abide by the transmission agreement of webpage content.
Web content is also called HTTP 超文本, so the transmission protocol of web content 超文本传输协议is also called HTTP protocol.

how to communicate

客户端The data should be passed to in the format required by the HTTP protocol 服务器, and then
服务器the data should be responded to in the format required by the HTTP protocol 客户端.

In other words, HTTP 请求,响应uses the way of interaction.

HTTP request message components

The http request message is divided into four parts:

  1. request line
  2. request header
  3. Blank line (a horizontal line is displayed on the page, which is used for 分隔请求头部和请求体)
  4. Request body ( , GET request has no request body)tips: 只有POST请求才有请求体

Use a picture to understand these four parts:
insert image description here
From the picture, we can see that , 请求行, 请求头部, are respectively composed.空行请求体

How to view http message requests in your own browser

We can right-click to check when the page initiates an ajax request, and view the specific http message request components in NETWORK网络面板.xhr

Components of the HTTP response message

http响应消息And http请求消息the same four parts:

  1. status line:
  2. Response header: (describe the basic information of the server)
  3. Empty line (used to separate the response header and response body)
  4. Response body (used to store the data content that the server responds to the client)

Use a diagram to describe the four components of the response message:
insert image description here

HTTP request method:

We often use the post, get, put, deletemethods, and of course some other methods, as shown in the figure below:

insert image description here

HTTP response status code

The role of the response status code is to identify the status of the response and let us know how it is responding now.

Each data request will return a response status, which starts with different numbers (eg:, 200 404etc.), and represents different meanings. Let's talk about the classification of status codes in detail

Response status code classification

Divided into five types: those starting with 1 (basically never encountered), those starting with 2, those starting with 3, those starting with 4, and those starting with 5;
insert image description here

2 at the beginning (representing 成功相关the response status code)

If we see this, it means the server has successfully received the request and processed it successfully. (there are two cases below)
insert image description here

3 at the beginning (representing 重定向相关the response status code)

There are three situations:
insert image description here

4 at the beginning (representing 客户端相关the response status code)

If there is a status code starting with 4, it means that 客户端there is an error in the request, which will cause the request to fail
insert image description here

5 (server-related response status code)

Indicates that the server failed to correctly process the client's request and an unexpected error occurred.
insert image description here
tips:The ones starting with 4 are 客户端errors, and the ones starting with 5 are 服务器端errors;
tips:only POST requests have request bodies, and GET requests have no request bodies.

Guess you like

Origin blog.csdn.net/egg_er/article/details/122708341