preface
Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”. Do you know anything about HTTP? You might say, “Well, it’s the Hypertext Transfer Protocol (HYPERtext Transfer Protocol), which regulates the communication between Web servers and browsers.” But what happens between the time a front-end request is sent and the time a response is returned to the server, do you want to say but don’t know where to start or what to say? This article carries on the analysis through two angles, the dry goods is full, today shares this small knowledge to everybody, MY humble opinion, also hopes everybody not stingy to give advice!
The body of the
Browser-based and server-based analytics
Send the request
When we type a legitimate URL into a browser, specifically called a Uniform Resource Locator (URL), there are all kinds of urls that not only allow us to access resources on the Web server, Also can use the browser to download and upload files on the FTP server, also have an email client function at the same time, can say that the browser is a have a variety of client function of comprehensive client software, so it needs specific identification to determine which function should be used to access the corresponding data, and a variety of different URL is used to do this.
Such as:
-
Access the Web server using HTTP
- https://[Web server domain name]:[port number]/[file path name]
-
Download and upload files using FTP
- ftp://[FTP server domain name]:[port number]/[file path name]
-
Send an email
- -Penny: I have a mail address.
-
Read the local file on the client computer
- File :/ [Local computer name (omitted)]/[Absolute path to local files]
Parsing the URL
To send an HTTP request, the first step of the browser is to parse the URL to generate a request message sent to the Web server. We have already mentioned that the URL can change depending on the protocol, so let’s look at what the browser looks like
As can be seen from the above figure, the URL parsing by the browser makes it clear that the path on the server to visit www.xxx.com is /.. / xx. The HTML file
For the resource file path can be omitted, some people may have a question, no table name file path server access to which file? In fact, we set the default file name on the server to be accessed when the file name is omitted. This setting varies from server to server, but in most cases it is a file name such as index.html or default.html
Generate an HTTP request message
After parsing the URL, the browser determines the Web server and file name, and then generates the HTTP request message based on these messages. In fact, HTTP messages are formatted strictly, so the browser generates the request message according to the specified format. The request message includes the HTTP version number, message header, and message body.
Return response message
After sending the request, the Web server returns a response message, which consists of a status code, response phrase, response header, and response body. The status code and response phrase are used to indicate whether the execution result of the request was successful, and they correspond to each other.
Summary of HTTP status codes
The first digit of the status code indicates the status type, and the second and third digits indicate the specific status
Status code | meaning |
---|---|
1xx |
Inform request processing progress and status |
2xx |
successful |
3xx |
Indicates that further operations are required |
4xx |
Client error |
5xx |
Server error |
When you return a response message, the browser extracts the data and displays it on the screen, and that’s where we can see what the web page looks like. If it returns text, it might end, but if it contains images or other resources, you have to make several requests to the server until all the resources are loaded. The server does not care whether the request comes from one web page or several web pages; its job is to return one response for each individual request.
So far, we’ve seen the general process of how a browser interacts with a Web server, from sending a request, to browser parsing, and finally to receiving and returning a response message, but is that the end of the article? No, no, no, no. That would be a little bit too long
Analysis based on network communication
You must have known about the computer network hierarchy model, which is a network communication protocol that must be relied on to achieve communication in the computer network, usually known as ISO/OSI reference model
Now, let’s look at the title again from this point of view. You send a request that is layered through the protocol to transmit a bit stream, routed to a Web server at the destination IP address, and then parsed by the server to return a response message. But you probably have no idea how much happens when you send a request from a computer to a target Web server!
In order to make you more clear and intuitive understanding of the communication process, I burst the liver of a flow chart for your reference:
At the end
Writing is not easy, welcome everyone to like, comment, your attention, like is my unremitting power, thank you to see here! Peace and Love.