In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what is the Http request process". In the daily operation, I believe that many people have doubts about what the Http request process is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the Http request process?" Next, please follow the editor to study!
Http introduction
Hypertext transfer Protocol (HTTP,HyperText Transfer Protocol) is the most widely used network protocol on the Internet. All WWW files must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages. In 1960, American Ted Nelson conceived a method of processing text information by computer, and called it hypertext, which became the foundation of the development of the standard architecture of HTTP hypertext transfer protocol.
The above is not the focus of this article. For a more detailed introduction to http, please move to www.baidu.com.
Http is not only a network protocol, but also a stateless hypertext protocol, an application layer protocol based on Tcp/Ip.
I want IP.
When a user requests the resources of a domain name, such as when the browser types in http://www.qq.com, the browser will first query the IP address based on the entered domain name. Where can I check it? Here we need to introduce the concept of DNS, which can be regarded as the account book of domain name mapping IP. When the client sends a DNS request, the local DNS server will first receive the request and query locally whether there is a mapping between the current domain name and IP in the cache. If so, the IP information will be returned directly. If not, other DNS servers will be asked. Here is a brief talk about the structure of the DNS server on the network. The DNS server is tree-like on the network, and there is a root server. The child node of the root server is the first-level domain name server (such as .com, .cn), and the child node of the first-level domain name server is also called the authoritative (permission) DNS server.
When the local DNS server does not have the relevant query information, it will query the corresponding relationship between the domain name and IP in the order of the above tree, and then cache it to the local DNS. The final result of this process is to obtain the IP address of the relevant domain name. If the client enters the IP address information, the above process of querying IP is omitted.
Any website that visits the Internet is essentially addressed according to IP.
Establish a Tcp connection
When a http request is made and the correct server IP address is obtained, the connection can be established. One thing to be clear: http protocol is based on Tcp protocol. So the first step is to establish a Tcp connection, which is what many online articles call a three-way handshake: Client:Hi, I'm Client. Server: Hello, Client, this is Server speaking. Client: Hello, Server....
Here is a three-way handshake that can be expressed in this order: client's question-> server's answer-> client's answer.
Some interviewers get bored and ask why three handshakes instead of two or four or five? You can understand that when two people An and B want to get in touch with each other, the easiest way is for A to ask questions and then receive B's answer, and B's question can receive A's answer. This is also the core of the three-way handshake.
The so-called Tcp is connection-oriented, but the connection here is actually a process in which both parties agree on a certain format for communication (including the order of sending packets, the size of the buffer, etc.). Logically, it seems to maintain a connection.
I'm going out of the gateway.
Once the Tcp connection is established, the http request can organize the data to send messages. The current version of the http protocol is mostly 1.1. in this version, there is an attribute Keep-Alive, which indicates the TCP connection to be established to maintain this http connection, which is enabled by default.
There are a lot of articles on the network describing the long connection information of http, which is actually wrong. Long connection is for tcp connection, and the keepalive option for http connection only keeps the tcp connection open.
The message of HTTP is roughly divided into three parts. The first part is the request line, the second part is the request header (header), the third part is the request body (body). Other concepts of the specific http protocol will not be discussed here because there is a lot of content. The http protocol is located in the application layer, so the message to be sent will first include the content related to the http protocol in the packet, and then pass it to the next layer.
The next layer is the transport layer, which mainly has two protocols: Tcp and Udp,http protocol choose tcp protocol, tcp will have two port information, one is the source port and the other is the destination port, for example, the general destination port of http request is 80. The transport layer encapsulates the port information and then transmits the request packet to the network layer.
The protocol in the network layer is the IP protocol, in which the source Ip address and the destination IP address are encapsulated (the target IP is the requested website ip, which is obtained by querying dns).
When the operating system knows the IP address to be sent, it will determine whether the ip is in the local LAN (based on the subnet mask). If not, the gateway needs to send the request (the ip of the gateway is generally configured by the DHCP protocol). How does the operating system get the gateway? This process basically depends on broadcasting, and the protocol applied is ARP. When all devices in the local area network receive the content of the ARP protocol, they will determine whether the ip is the same as the gateway ip, and if the same, they will reply. After this process, the system finds the gateway, obtains the gateway's MAC address, and encapsulates the gateway's MAc address and the local MAc address into the request packet. Send it to the next MAC layer, and finally the network card sends the message to the gateway.
The MAC address is mainly used to locate a computer in the same local area network, which is only valid in the local area network.
Reach the target server
When the request packet arrives at the gateway, the gateway will judge whether it is the same as its own mac according to the MAC address of the message, and if so, it will receive the message. Then it determines the destination IP in the message, and if the destination IP is not in its own local area network, it needs to send the message to the next connected gateway according to its own routing rules. There is communication between the gateway and the gateway, as for how the gateway calculates the optimal path, it is no longer expanded here. Let's take the common home router as an example, the gateway IP of each router is actually assigned by the operator, and the network packets are generally sent out by modifying the IP (NAT). Specific steps:
The gateway checks whether the destination IP is in its own local area network. If not, it gets the next gateway mac and IP to be transmitted, modifies the destination IP and mac to the IP and mac of the next gateway, and modifies the source IP and mac to the IP (external network IP) and mac of the current gateway.
When the next gateway receives a message, it first checks whether the mac matches itself. If it matches, it will check whether the target IP is in its own LAN. If not, repeat the above steps.
Repeat the above steps to the gateway where the target server is located.
When the gateway of the target server receives the message, it will determine that the current target IP is within the scope of my local area network, so it will not jump the next gateway, but send ARP requests to the local area network to find the target server. The target server will respond to the request, and the gateway will send the specific request to the target server.
The target server will parse the requested message when it receives the message. After comparing the mac and IP information, the target server will get the port information. The target server will look for programs listening on this port locally. The http server is likely to be nginx or other web servers.
The request is sent to the specific processing program through the port, and the program will parse the content of the http request and reply accordingly according to the content.
The request follows all the steps above to return the response to the requestor (the gateway router remembers the source path), and the http request ends.
The gateway (router) determines the address of the next hop through the routing table.
At this point, the study of "what is the Http request process" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.