1. Four-layer model
+
2.socket
3.http protocol
4. HTTP requests
Following Sina's homepage, let's summarize the process of the HTTP request:
3.1.1 Step 1: The browser sends an HTTP request to the server first, and the request includes:
Method: Get or Post,get only request resources, Post will be accompanied by user data;
Path:/full/url/path;
Domain name: specified by the Host header: Host:www.sina.com
and other relevant headers;
If it is post, then the request also includes a body containing the user data
3.1.1 Step 2: The server returns an HTTP response to the browser, and the response includes:
Response code: 200 indicates success, 3xx indicates redirection, 4xx indicates that the client sent a request error, 5xx indicates server-side processing error occurred;
Response type: specified by Content-type;
and other relevant headers;
Usually the server's HTTP response will carry content, that is, a body, containing the content of the response, the HTML source of the Web page is in the body.
3.1.1 Step 3: If the browser still needs to continue to request additional resources from the server, make the HTTP request again, repeat steps 1, 2.
The HTTP protocol used by the web uses a very simple request-response pattern, which greatly simplifies development. When we write a page, we only need to send the HTML in the HTTP request, no need to consider how to include pictures, videos, etc., if the browser needs to request pictures and videos, it will send another HTTP request, so an HTTP request only processes one resource ( This can be understood as a short connection in the TCP protocol, with each link acquiring only one resource, if multiple links need to be established.
The HTTP protocol is also very extensible, although the browser is requesting the http://www.sina.com
homepage, but Sina in HTML can be linked to other server resources, for example
, so that the request pressure spread across the server, and a site can link to other sites, Countless sites link up with each other, forming the world Wide Web, referred to as www.
1 HTTP protocol