Some time ago, while chatting with an old classmate I haven’t seen for a long time, I was suddenly asked what the HTTP protocol is? What comes to mind for the first time is words like request, response and so on. But can he really know what it is? I asked myself, so I looked for relevant materials to study. In fact, most programmers are always trying to move bricks every day. I believe few people have seriously studied what HTTP protocol is?
HTTP protocol, also known as hypertext transfer protocol, is an application layer protocol for distributed, collaborative and hypermedia information system, which is the basis of network interconnection. We usually know the HTTP protocol. To put it bluntly, we just know how to use it in programming, but in fact, the underlying implementation of HTTP protocol is extremely complex. It extends to the top application layer protocol through seven layer network architecture or five layer network architecture. Network architecture is not the focus of our research, but at least we need to know the basic principle of TCP protocol, why TCP protocol is mentioned here, because TCP protocol belongs to the application layer, and HTTP protocol is an encapsulation of TCP protocol.
Next, let’s see how the HTTP protocol works. After an HTTP request is sent to the server, a TCP socket connection will be established first, and then the server will receive the request message from the client, the server will complete the parsing of the message, that is, know what the request wants to do, and then the server will return the content information required by the client request to the client At the same time, it will return TCP connection status and other information. After the client gets the information, it will analyze it. Before that, the response has been completed and the corresponding connection will be released. Note: if the domain name is requested, the domain name server will be accessed to complete the domain name resolution before the TCP socket is established.
Here are some interesting pictures to illustrate the HTTP protocol request process.
The above two interesting figures show the general request process of HTTP protocol.
In addition, HTTP protocol is a stateless protocol. In other words, the HTTP protocol itself does not save or persist the communication state between the request and the response, and it will disconnect after completing a request and response operation.
In daily coding, HTTP requests mainly define eight methods to execute requests. That is, the post, get, put, delete, etc. of HTTP request in my mind when my friend asked. These contents are only the methods that HTTP request process can be used to operate server resources, not the concept or principle of HTTP request.
More highlights go to Laowang programming > > >