【Recommended course: http tutorial】
http request process is:
(1) Establish TCP connection
Before the HTTP work starts, the web browser must first communicate with the web server through the network Establish a connection, which is completed through TCP. This protocol and the IP protocol jointly build the Internet, the famous TCP/IP protocol, so the Internet is also called the TCP/IP network. HTTP is a higher-level application layer protocol than TCP. According to the rules, higher-level protocol connections can only be made after the lower-level protocol is established. Therefore, a TCP connection must be established first. Generally, the port number of the TCP connection is 80. To establish a TCP connection, you need to find the connecting host, so you need to first resolve the domain name to get the IP, then find the host and perform a 3-way handshake to establish the TCP connection (establish a communication bridge between the two computers)
(2) Web browsing The browser sends a request command to the Web server
Once the TCP connection is established, the Web browser sends a request command to the Web server. For example: GET/hello/index.jsp HTTP/1.1. After the browser sends its request command, it also sends some other information to the Web server in the form of header information (for example: Accept, User-Agent, etc.), and then the browser sends a blank line to notify the server that it has ended. The sending of this header information.
(3) Web server response
After the client sends a request to the server, the server will respond to the client , the response content includes: protocol version number and response status code: HTTP/1.1 200 OK, response header information to record the server's own data and the requested document content. Finally, a blank line is sent to indicate that the sending of header information has ended, and then the actual data requested by the user is sent in the format described by the Content-Type response header information.
(4) The Web server closes the TCP connection
Under normal circumstances, once the Web server sends the requested data to the browser, it will close the TCP connection, but If the browser or server adds this line of code to its header information: Connection:keep-alive
The TCP connection will remain open after sending, so the browser can continue to send requests through the same connection. Keeping connections saves the time required to establish a new connection for each request and also saves network bandwidth.
(5) The browser receives the data responded by the server
The browser accepts the html code and css returned by the server, and js code to render the page or save the response file.
Summary:
A complete http request process can be divided into The following parts:
The browser initiates a request-> Parses the domain name to obtain the IP for TCP connection->The browser sends an HTTP request and header information->The server responds to the browser and responds with the header information And the content required by the browser-> Close the TCP connection or keep it-> The browser gets the data data to operate.
The above is the detailed content of What does the http request process include?. For more information, please follow other related articles on the PHP Chinese website!