Wechat official account: [Dafront-end Post] follow Dafront-end Post. Questions or suggestions, welcome to leave messages on the public account.
How does the browser work after we type in a web address or click on a link in a web page? The above question is a routine question in the interview, but in the interview can describe it clearly the students are not many, today we will discuss.
What is a URL for
We usually use the browser to access the Web server, but in fact the browser is not the only function, it can also be used to download and upload files on the FTP server, and also has the function of an E-mail client. Browser is, as it were, a have a variety of client function of comprehensive client software, so it needs something to determine which kind of function should be used to access the corresponding data, and a variety of different URL is used to do this, such as access to the Web server in the “HTTP:”, and “FTP:” are used when access to the FTP server.
Although there are many different ways to write urls, they all have one thing in common: the words at the beginning of the URL, namely “HTTP:”, “FTP:”, “file:” and “mailto:”, all indicate the access method that the browser should use
Browser parses URL
The browser’s first step is to parse the URL to generate a request message to send to the Web server.
When a URL is parsed, it first needs to be broken down into the individual elements in the format of figure (a), for example, the URL in Figure (b) would be broken up into figure (C). Then, by splitting these elements, we can understand what the URL stands for
The URL in figure (b) above indicates accesswww.lab.glasscom.com/dir/file1.html on the Web server, that is, file1.html in /dir/ D
Note: The default file name to access when the file name is omitted is set on the server. This setting varies from server to server, but in most cases it is a file name such as index.html or default.htm. Therefore, when the file name is omitted as above, the server accesses /dir/index.html or /dir/default.htm.
Generate HTTP request messages
Query the IP address of the Web server from the DNS server
Although the browser can parse web addresses and generate HTTP messages, it does not have the ability to send messages to the network itself, so it has to delegate this function to the operating system. When you delegate a message to the operating system, you must provide not the domain name of the communication object, but its IP address.
There must be a CORRESPONDING DNS client on our computer, and the equivalent part of the DNS client is called a DNS parser, or simply a parser. The operation of querying an IP address through the DNS is called domain name resolution. Therefore, the person responsible for performing the resolution operation is called a resolver
After the parser is invoked, the parser sends a query message to the DNS server, which then returns a response message. The response message contains the queried IP address, which is extracted by the parser and written to the memory address specified by the browser. By running the one-liner in Figure 1.11, we can do all of this, and we are done with the IP address query. Then, when the browser sends a message to the Web server, it simply retrieves the IP address from that memory address and passes it along with the HTTP request message to the operating system
You send a request and receive a response
When we send the above request message, the Web server returns a response message. In the response message, the first line contains the status code and the response phrase, indicating whether the request execution results in success or error. Status codes and response phrases say the same thing, but they serve different purposes. A status code is a number that tells a program the result of its execution. A response phrase, by contrast, is a piece of text that informs people about the outcome of an execution.
Summary of HTTP status codes
When the response message is returned, the browser extracts the data and displays it on the screen, and we can see what the web page looks like. If the content of the Web page only text, then here are all processed, but if there are any pictures related labels, will set aside to show pictures of the space on the screen, then access the Web server again, according to the label of the specified file name to the Web server requests to obtain the corresponding pictures and displayed in the reserved space. The procedure is the same as getting a web page file, just write the file name of the image in the URI section and generate and send the request message.
Only one URI can be written in a request message. If you need more than one file, you must send a separate request for each file. For example, a Web page contains three pictures, so get the Web page and get the picture, a total of four requests to the Web server
【 Share, like, watch 】 three consecutive, let more people join us ~~