The HTTP communication mechanism is that during a complete HTTP communication, the following 7 steps will be completed between the Web browser and the Web server:
1. Establishing a TCP connection
Before HTTP work begins, the Web browser first establishes a connection to the Web server over the network, which is done through TCP, which works with the IP protocol to build the Internet, known as the TCP/IP protocol family, so the internet is also known as a TCP/IP network. HTTP is a higher level of application-level protocol than TCP, according to the rules, only the lower layer protocol is established before the protocol can be more connected, so the first to establish a TCP connection, the port number of the general TCP connection is 80.
2. Web browser sends request command to Web server
Once a TCP connection is established, the Web browser sends a request command to the Web server. For example: get/sample/hello.jsp http/1.1.
3. Web browser sends request header information
After the browser sends its request command, it also sends some other information to the Web server in the form of header information, and then the browser sends a blank line to notify the server that it has ended sending the header information.
4. Web server Answer
After the client makes a request to the server, the server responds back to the client, http/1.1, and the first part of the answer is the version number of the protocol and the response status code.
5. The Web server sends the answer header information
Just as the client sends information about itself along with the request, the server also sends the user with the answer about its own data and the requested document.
6. The Web server sends data to the browser
After the Web server sends the header information to the browser, it sends a blank line to indicate that the header information is sent to the end, and then it sends the actual data requested by the user in the format described in the Content-type reply header information.
7. The Web server shuts down the TCP connection
In general, once the Web server sends the request data to the browser, it closes the TCP connection and then if the browser or server joins this line of code in its header information:
Connection:keep-alive
The TCP connection remains open after it is sent, so the browser can continue to send requests through the same connection. Maintaining a connection saves the time it takes to establish a new connection for each request and also saves network bandwidth.
Reprint: 7 Steps experienced by a complete HTTP request
7 steps to a complete HTTP request