[HTTP] What happened after I entered the URL in the browser?

We all know that after entering www.baidu.com in the web address field of the browser and clicking Enter, Baidu's homepage will appear. Then take a deeper look, how did you make the correct request for resources during this period, and what else happened?

Network model

Before answering the question, let's review the network model. We usually have the following two common network models:
1. The seven-layer model of OSI (Open System Interconnection)
Insert picture description here

2. The four-layer model of TCP/IP:
Insert picture description here

Among them , I have written about the application layer , transport layer , and network layer in detail. If you are interested, you can click on the link to understand. Now we take the four-layer model as an example to officially enter the topic.

Happening

Through the diagram of the four-layer model, we should know that the following processes will probably occur after entering the URL:

  1. The application layer uses DNS to resolve the domain name to obtain the target IP address. Next, the content is obtained by looking up the target IP through DNS. If this IP is stored locally, it is used directly; if not, it will ask the higher-level DNS server for help until the content of the target IP is obtained. The detailed process of DNS domain name resolution is explained below.
  2. The application layer loads the requested information into the HTTP request message (down-encapsulation process), including the first line of the request (method + url) + request header (+ blank line) + request body, and then the application layer initiates this HTTP request.
  3. The transport layer receives the data passed by the application layer, and divides it into data packets in units of message segments for management, and numbers them so that the server can accurately restore the message information when receiving it. Establish secure communication with the target port through a three-way handshake .
  4. The network layer receives the data transmitted by the transport layer and performs routing (IP search for the target network + ARP search for the target host), that is, obtain the physical address of the target computer—MAC through the ARP protocol according to IP. When the two parties of communication are not in the same local area network, multiple transfers are needed to reach the final destination. During the transfer process, the MAC address of the next transfer station needs to be used to search for the next transfer target.
  5. After the target MAC address is found, the data is sent to the server through the data link layer , and then the real transmission request information starts, and the request ends after the transmission is completed.
  6. After the server receives the data, it unpacks and separates the data from the bottom to the upper layer until the application layer.
  7. Find the resource requested by the client on the server, load the data into the HTTP response message and return it the same way. The response message includes an important information-the status code, such as 200, 404, 500.
  8. The browser receives the message content to view the status code. If 200, the page will be parsed and rendered according to the content of the response message, and the corresponding error will be displayed for other status codes.
  9. The TCP connection is released and the request is completed.

DNS domain name resolution

The search process of DNS domain name resolution mainly includes the following steps:

1. Browser cache-the browser will cache DNS records for a period of time

2. System cache-If the required record is not found in the browser, the browser will make a system call, using gethostbyname, to obtain the record in the system cache

3. Router cache-If the system cache is not available, the query request will be sent to the router, which generally has its own DNS cache.

4. ISP DNS cache-The next thing to check is the ISP cache DNS server, where you can generally find the corresponding cache records.

5. Recursive search-your ISP's DNS server starts recursive search from the root domain name server

If you want to know more about the resolution process, I also wrote a blog about the DNS domain name resolution process . Welcome to check it out~

Guess you like

Origin blog.csdn.net/ly_6699/article/details/112985179