I. Web and Network foundation
1. The browser enters the content address and returns the content you want. Web from the client to the server a series of operational processes are built on the HTTP protocol for communication.
HTTP was originally created for the purpose of sharing knowledge among researchers around the world
- Http0.9 (introduced in 1990, not officially a standard)
For 0.9, which is the original Internet era, when browsing the web in the browser, you can see some static pages, that is, there is no interaction page. Business profiles, for example, do not change and can only be used as a browse.
At this point, the HTTP protocol has only one command, Get
- Http1.0 (1996, official standard)
For example, this time the site can register users, there is more interaction; The server is no longer a single HTML document, a variety of animations appear; The page has information such as cache.
The HTTP protocol added many commands (post, etc.), status codes and headers, caching, and multi-character support.
- HTTP 1.1 (1997, current mainstream version of the HTTP protocol)
Added pipes, persistent connections, host, and a few other commands
- Http2.0 (first tested in 2013, future tense)
Multiplexing request; Prioritize requests; Compress HTTP header; Server Push flow (Server Push technology);
3. For computers and network equipment to communicate with each other, they must do so in the same way. For example, rules about how to detect a communication target, which side initiates the communication first, which language to use, and how to end the communication need to be determined in advance. Communication between different hardware, operating systems, all of which require a set of rules called protocols.
4. The TCP/IP protocol family is divided into the following four layers: the application layer, the transport layer, the network layer and the data link layer.
- The application layer
The application layer determines the communication activities when providing application services to users. Common application services are stored in the TCP/IP protocol family. For example, File TransferProtocol (FTP) and Domain Name System (DNS) services are two of them. The HTTP protocol is also at this layer.
- The transport layer
The transport layer provides data transmission between two computers in a network connection to the upper application layer. There are two different protocols at the transport layer: Transmission Control Protocol (TCP) and User Data Protocol (UDP).
- Network Layer (also known as network Interconnection Layer)
The network layer processes the data packets that flow across the network. A packet is the smallest unit of data transmitted over a network. This layer specifies the path (the so-called transmission route) through which to reach the other party’s computer and transmit packets to the other party. The role of the network layer is to select a transmission route from a number of options when transferring between computers or network devices.
- Link Layer (also known as data link layer, network interface layer)
It handles the hardware that connects to the network. This includes device drivers that control the operating system, hardware, NIC (Network Interface Card, that is, Network adapter), and physical visible parts such as optical fibers (and all transmission media such as connectors). Hardware categories are within the scope of the link layer.
5, TCP/IP communication transmission flow
First, the client uses the client to send HTTP requests at the application layer and enters the transport layer. In order to facilitate transmission, this layer divides THE Tttp request packets, marks the number and port of each packet, and forwards the packets to the network layer. The network layer adds the MAC address of the destination and sends it to the link layer. This is the transmission of an HTTP request. When sending, it will be marked with this layer, and then when receiving, it will peel off the outer layer one by one and eliminate the head mark.
6. IP protocol, which is closely related to HTTP, is introduced
As shown in the figure above, the IP protocol is located at the network layer. It is a protocol that cannot be confused with the IP address. The function of IP protocol is to send various data packets to each other. The most important two conditions are the IP address and MAC address. The IP address indicates the address assigned to the node. The IP address can be changed, and the MAC address is the fixed address of the network adapter.
IP communication depends on the MAC address. The MAC address can be regarded as a relay station, through which communication is completed. The translation of IP addresses to MAC addresses depends on ARP, which can resolve addresses.
7. TCP is one of the three protocols closely related to HTTP
As shown above, the TCP protocol sits at the transport layer and provides a reliable byte stream service. A reliable byte stream service is one that separates large chunks of data into packets. Reliability means that data can be sent to the other side accurately and reliably, unlike UDP.
The TCP protocol uses the three-way handshake policy. After sending a packet using TCP protocol, TCP will not ignore the situation after the transmission, it will confirm to the other party whether the delivery was successful. The TCP markup SYN and ACK are used during the handshake.
The sender sends a packet with the SYN flag to the receiver. After receiving the packet, the receiver sends a packet with the SYN/ACK flag to convey the acknowledgement. Finally, the sender sends back a packet with an ACK flag, which indicates the end of the handshake.
8. DNS protocol is introduced among the three protocols closely related to HTTP
DNS is an application layer protocol. Many domain names, such as www.baidu.com, are supported by many servers. Each server has an IP address. The service responsible for looking up IP addresses by domain names, or for backchecking domain names, is DNS.
Two, simple HTTP protocol
1, HTTP protocol, must be one end as the client role, the other end as the server role. The end that requests access to a resource such as text or images is called the client, and the end that provides the response to the resource is called the server.
2. Structure of request packet and response packet
3. HTTP is a stateless protocol that does not have the ability to save previously sent requests or responses. For example, a shopping site that jumps to another page will log out if there is no other page to guarantee the login status, because HTTP does not save the state.
4. HTTP request method
5. Persistent HTTP connections
This function can be used in the following scenarios: When a page has multiple requests, a TCP connection is usually required for each communication. Therefore, each request causes unnecessary TCP connection establishment and disconnection, increasing traffic overhead. Multiple requests require repeated operations of establishing, requesting, and disconnecting, affecting communication overhead.
Thus, Http1.1 introduced a persistent connection, also known as keep-alive, which is characterized by staying connected as long as either end does not explicitly request to disconnect.
6. Cookie state management
We said earlier that HTTP is a stateless protocol. The goal is to be efficient and quick, without burdding the client state, which is sometimes needed, so the cookied technology is introduced. A request sent with a cookie will be remembered by the server, and the server will know that this time it is the same guy who sent the request.
Request message:
Response message (server generates cookie) :
Request message (automatically send the saved Cookie information) :
3. HTTP information in the HTTP packet
The HTTP communication process includes sending a request from the client and a response from the server to the client. This chapter focuses on the request and response process
1. Message structure
The information used for HTTP protocol interactions is called HTTP packets,
2. HTTP data can be encoded to improve the transmission rate and effectively handle a large number of access requests.
4. HTTP header
The HTTP request and response packets must contain the HTTP header.
1. The header contains a large number of important fields. The header field consists of the name and value of the header field, separated by colons (:). Such as:
Content-Type:text/html
Copy the code
2, the first field overview