http basics excerpt

HTTP is a stateless protocol based on the request/response mode (only the client sends a request and the server will respond, otherwise the server will not actively send information, stateless means that the client sends a request and the server sends you back a Response, and then you send another request. The server has no idea whether your request was sent for the first time or the second time. It has no idea what happened last time or in history. It only knows about you. Send me a request and I will give you a response. Therefore, in some shopping systems or login systems, it is necessary to know whether the user is logged in, so cookies and sessions are derived to record client information)

The HTTP protocol is based on TCP, so a connection must be established, similar to a database connection

HTTP/1.0: When the connection is established, the browser sends a request, the server returns a message, and then the connection is closed. When the browser makes the next request, it needs to re-establish the connection. Obviously, this kind of communication overhead that requires continuous connection establishment Relatively large, early web pages usually only contain HTML text, so even if the overhead of establishing a connection is relatively large, it will not have much impact (fewer requests are sent in essence), while current web pages often contain multiple resources (images , animation, sound, js, css, etc.) every time a resource is acquired, a connection is established, which increases the overhead of the HTTP server and causes information blocking on the Internet. (In essence, there are more requests sent, and it is not appropriate to use one request for one connection). For example, if a web page is requested to contain 100 pictures, 101 connections need to be established according to the HTTP/1.0 method. First, the server will return a response (ie, a web page), and then the browser will find that it needs to send 100 requests according to the content analysis to get 100 pictures, which is why when we visit web pages with many pictures, a web page will be displayed first, and then pictures will be slowly displayed one by one.

HTTP/1.1 gives the mechanism of persistent connections (Persistent Connnections) and uses it as the default behavior of establishing connections in HTTP/1.1. Through this connection, the browser can send requests and get responses after establishing a connection. Then continue to send the request and get a response again, and the client can also send a pipeline request, that is to say, the client can send multiple requests in a row without waiting for the arrival of each response (the efficiency of pipeline requests is obviously higher than that of one response and one response) , that is to say, the connection is not closed immediately after the request is responded, and it can be maintained for a period of time. The example of 100 pictures uses the HTTP/1.1 protocol and only needs to establish a connection, which greatly improves the performance.

Each time the client and server establish and close the connection is a relatively time-consuming process, and can seriously affect the performance of the client and server.

The client requests access to the resource from the server by sending an HTTP request

An HTTP request consists of three parts: the request line, the message header, and the request body

Entering the address in the address bar of the browser to send an HTTP request to the server is essentially that the bottom layer first establishes a connection with the server and then sends an HTTP message.

HTTP request line contains Method Request-URI HTTP-Version (CRLF)

In HTML documents, writing get and post is not case-sensitive, but GET and POST in HTTP protocol can only be in uppercase

The HTTP response also consists of three parts: the status line, the message header, and the response body

The information corresponding to each status of the HTTP response:

1XX - Indication information, indicating that the request has been accepted, continue processing

2XX - success, indicating that the request has been successfully received, understood, accepted

3XX - redirection, further action must be taken to complete the request

4XX - client error, the request was made by a syntax error or the request could not be fulfilled

5XX - Server-side error, the server failed to fulfill a legitimate request

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325971355&siteId=291194637
Recommended