Easily understand the HTTP protocol

Why learn network protocols? Why finish studying computer? Obviously this is important, or at least one of the reasons why you can get a job, because there are so many things to learn online that you can’t memorize them quickly.


Understand the network protocol, should start from the background principle. So please read carefully from now on! Suitable for the crowd, the computer has the corresponding understanding, the introduction of software technology friend.



What happens when you send a request from the client? The normal status code is 2XX, the error status code is 4XX, or 5XX, etc.



Error 404:




Understand the Web, understand the basics of the network, understand the HTTP protocol, how to use the HTTP protocol to access the Web, we in the computer browser Web page is how to query, the Web browser in the address bar enter THE URL address, you can display the page, this is also our understanding of common sense.


Enter the URL in the address bar of the browser, and you can see the Web page. That is, after the client enters the URL in the address of the browser, the information will be sent to somewhere, and then the reply from somewhere will be displayed on the Web page.


Client: Web browsers such as these that send requests for server resources are called clients.


The Web page we see is not just displayed for us to see, it is sent according to the URL you specify in the address bar of the Web browser, the Web browser from the Web server to obtain file resources and other information, and then returned from the server to display the Web page on the Web browser.


There are two topics, the Web browser as the client, one for the server, the Web browser through the specified access address to obtain resources on the server, the server uses HTTP protocol communication back to the Web browser.


The Web is built to communicate over HTTP, the hypertext Transfer protocol as a specification (or more accurately, hypertext transfer protocol) that completes a series of workflows from client to server, protocol refers to the convention of rules.


What is the client side versus the server side? In simple terms, the client is a personal computer, and the server is a server, through the computer to access the resources on the server, using the HTTP network protocol.


So what is HTTP protocol?


HTTP is called hypertext Transfer Protocol (HTTP), which is an application-layer protocol of TCP/IP and is used to define the process of data exchange between Web browsers and Web servers. If a client wants to obtain a Web resource from the Web server after connecting to the Web server, it must comply with a certain communication format. The HTTP protocol is used to define the communication format between the client and the Web server.



HTTP appeared in 1989, the Internet is a few people, in order to commit to the world’s researchers knowledge sharing, HTTP was born, someone put forward an idea to let researchers from distant places to share knowledge, with the help of the hypertext formed by the correlation between multiple documents, connected into the WWW, the World Wide Web can refer to each other.


The three WWW construction techniques are:


SGML: Standard Generalized Markup Language

Standard General markup Language


HTML: HyperText Markup Language

Hypertext Markup Language


HTTP: HyperText Transfer Protocol

Hypertext transfer protocol


URL: Uniform Resource Locator

Uniform resource locator


  1. HTML using SGML as the text markup language for pages;

  2. HTTP as a document delivery protocol;

  3. The URL that specifies the address of the document


HTTP is the multimedia messenger of the Internet. How many pictures, pages, files, movies, audio files and other resources are on the Internet every day, HTTP can quickly and reliably move this information from Web servers all over the world to people’s Web browsers.


Web client and server. Web content is stored on the Web server using the HTTP protocol. If the HTTP client makes a request, the server will provide the data in the Internet.


HTTP clients and HTTP servers together form the basic components of the World Wide Web.


Web server is the repository of Web resources, Web resources are the source of Web content, Web resources can contain any content, all content is provided by Web resources.



The URI and URL


Each Web server resource is given a name, so that the client can select the resource it wants. Uris, server resource names, are uniform Resource Identifiers (UrIs). Uris are names, like postal addresses on the Internet, that uniquely identify and locate information resources worldwide. Uris come in two forms, URLS and UrNs.


A UNIVERSAL resource Locator (URL) is the most common form of a resource identifier. It describes the specific location of a resource on a specific server. URN is a universal resource name that is used in a wide range of applications.


For computers and network devices to communicate with each other, they have to communicate in the same way, with different hardware and operating systems, all of which require a rule. This rule is called a protocol.



TCP/IP is the general name of various internet-related protocol families. TCP/IP refers to TCP and IP. TCP/IP refers to the protocol family used in IP communication.



Layered management of TCP/IP

The TCP/IP protocol family is divided into application layer, transport layer, network layer, data link layer, and physical layer. It can be divided into 4 or 7 layers, depending on the model.


TCP/IP is divided into five layers, closer to the hardware as you go down.


Application layer, the application program receives the data of the transmission layer, the next is to interpret, interpret must first define the format, and the application layer is to specify the data format of the application program, the main protocol is HTTP and so on.


The transport layer, which provides end-to-end communication between applications on two hosts, has two transport protocols: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). TCP is a reliable connection-oriented protocol, while UDP is an unreliable or connectionless protocol.


The network layer, which determines how data is transferred from sender to receiver, establishes host-to-host communication.


The data link layer controls the communication between the network layer and the physical layer and ensures reliable data transfer on the physical line.


The physical layer, which is responsible for the physical transport and is related to the link as well as the transmission medium.





After the TCP/IP protocol is layered, if you need to change some parts of the design later, you only need to replace the changed layer.


The TCP/IP protocol family is divided into the following layers: application layer, transport layer, network layer, and data link layer.


Application layer, the application layer determines the communication activities when providing application services to users, such as FTP, file transfer protocol, and DNS service. HTTP protocol is in the application layer.


The transport layer, the transport layer to the upper application layer, provides data transfer between two computers in a network connection, including TCP transmission control protocol and UDP user datagram protocol.


The network layer, used to process packets as they move across the network, specifies which route to take the packets to the other computer.


The link layer is used to deal with the hardware part connected to the network, including the operating system, hardware device driver, NIC, etc.


The above content is too conceptual, understand and understand:


And how did they write to each other?




When the TCP/IP protocol family is used to communicate with each other on the network, the sending end goes from the application layer (HTTP client), transport layer (TCP), network layer (IP), and link layer (network), while the receiving end goes from the link layer up.


When transmitting between layers, each layer must be printed with the header information of the layer, conversely, when receiving data, the receiver will remove the corresponding header after each layer, which is called “encapsulation”.


See text content by the figure, this I believe we must understand.


Transport layer, TCP/UDP, TRANSMISSION Control Protocol and User Datagram Protocol. Again, TCP is a reliable connection-oriented protocol, while UDP is not a reliable, or connectionless, protocol.


TCP and UDP are transport layer protocols. The differences between them are as follows:


TCP reliability is strong, it is reliable, connectivity, and is a connection-oriented packet, is a byte stream oriented, efficiency, the transmission efficiency is low, duplex, full duplex, flow control is a sliding window, congestion control is a slow start, congestion avoidance, fast retransmission, fast recovery, transmission speed is slow, application scenarios on efficiency is low, Scenarios that require high accuracy or connections.


UDP is not reliable, connectionless, message-oriented, efficient, one-to-one, one-to-many, many-to-one, many-to-many, flow control, none, congestion control, none, but the transmission speed is fast, and the application scenario requires high efficiency and low accuracy.


Benefits of TCP/IP layering


If there is only one protocol on the Internet, and something needs to be changed, then the whole thing has to be changed, but after layering, you just need to replace the changing layers.



TCP’s three-way handshake and four-way wave

Look at the picture and remember that there are three arrows and four dialogs to remember the formula:


Three handshakes and four waves:



Schematic diagram of three-way handshake:



Three-way handshake process:


The first handshake is the establishment of a connection. The client sends a connection request packet and sends the packet marked with SYN to the server as the receiver.


In the second handshake, the server or receiver receives a SYN packet from the client and sends a packet marked with SYN/ACK.


After receiving the SYN/ACK packet from the server, the client sends the packet marked WITH ACK to the server.


The above explanation looks at the picture together to understand better, between the transmission of data.


TCP’s three-way handshake, so do you know what TCP is? I’m sure some of you remember, but some of you forget, understand the TCP header, and why the TCP three-way handshake, and not some other number? What are the differences or changes in the TCP three-way handshake?


TCP, the transmission control Protocol (TCP), is a connection-oriented, reliable, byte stream based transport layer communication protocol. Do not understand baidu.


[TCP/IP] Indicates the TCP packet header

A message is a data unit exchanged and transmitted on a network. It is a block of data that a site sends at a time. A message contains complete data information to be sent, and its length is variable and unlimited.



Let’s take a look at the explanation of “packet” on Baidu:


Understanding and functions of packets

Packets are used to exchange information between systems in request and response, and must comply with the specified format.

In addition, application messages are mostly when multiple systems need to communicate, such as the BANK’s ESB system to the gateway system and then to the UnionPay system. In this intermediate message assumes the function of loading and transporting data. The format of the message may be different in the three systems, but the data carried is the same.



TCP header message


Source port, the source port number, pointing to the local port

Destination port indicates the destination port number, pointing to the remote port


The source port number is the sending port, and the receiving port is the destination port number. The source port number is sent from the sending port to the receiving port according to certain rules. Different applications have different ports, because the sending port sends many source ports, corresponding to the receiving port many corresponding rules of the destination port number.


Sequence Number


It is used to transmit byte streams in a segmented sequence during TCP communication. The receiving end reorders byte streams according to the sequence number. If everyone in the queue takes the corresponding number of entrance check, after entering the same will not sit in disorder.


TCP has six states:


SYN(establish connection) ACK(confirm) PSH(transmit) FIN(end) RST(reset) URG(urgent)Copy the code


Analyze the TCP three-way handshake

First client, server, TCP three-way handshake:


TCP flags, SYN and ACK, are used in the handshake.


Initialization state: The client is closed and the server is listening.


First handshake: The client sends a request packet and sends SYN=1 and seq=x to the server. The server creates a connection in the initial state, waits for the client, and then confirms the status as SYN_Receive. The client is in the wait state of SYN_Send.


On the second handshake, after the server receives a packet (SYN=1, SEq = X), the request packet changes to SYN=1, initial SEQUENCE number SEq =1, ACK=1, ACK= X +1. The server is in the SYN_Receive state, and the sender is in the SYN_Send state.


For the third handshake, the client receives the packet from the server (after receiving the response), and then sends an acknowledgement packet with the serial numbers ack= Y +1 and the serial numbers SEq = X +1 and ACK=1 as a reply (for the third handshake: ACK=1,seq=x+1, ACK= y+1), the client and server state changes to Established.


I sent three messages to my girlfriend. These three handshakes are mainly to verify that there is no problem with the ability of sending/receiving messages between my girlfriend and me, to prove that the connection is normal and I can formally send messages.


The first handshake, I send a message, girlfriend received, at this point girlfriend knows, MY ability to send a message and her own ability to receive the message is no problem.


On the second handshake, my girlfriend sent a message, and I received it. At this time, I understood that there was no problem with my sending and receiving messages, or I had to shake hands for the third time. If there was no reply from me, my girlfriend still didn’t know whether there was no problem with her sending messages.


The third time I shook hands, I sent a message, my girlfriend received, at this time my girlfriend also confirmed that there is no problem between us to send and receive the letter.


DNS service responsible for domain name resolution


DNS is located at the application layer like HTTP. Provides domain name resolution services to IP addresses. The DNS provides the service of searching IP addresses by domain names or reverse-searching domain names from IP addresses.


The relationship between various protocols and THE HTTP protocol



When the client and server establish a TCP connection through the three-way handshake, when the data transfer is complete, the TCP four-way handshake is required to disconnect the connection.


The four waves are as follows:



First wave


The client sets seQ and ACK and sends a FIN=1 packet segment to the server. At this point, (first wave, FIN=1, seq= U) The client enters FIN_WAIT state, indicating that the client has no data to send to the server.


Second wave


The server received the FIN packet from the client and returned an ACK packet to the client.


Third wave


The server sends a FIN packet to the client to close the connection and enters the LAST_ACK state.


Fourth wave


After receiving the FIN packet from the server, the client sends an ACK packet to the server and enters the TIME_WAIT state. After receiving the ACK segment from the client, the server closes the connection. At this point, the client waits for 2MSL (the maximum lifetime of a fragment in the network) and still does not receive a response, indicating that the server has been properly shut down and the client can close the connection.


Uniform Resource Identifier (URI)

Uris are Uniform Resource Identifiers. Specifying a Uniform format makes it easy to handle multiple types of resources without having to identify specific access methods for resources based on context.


Uniform Resource Locator (URL), which is the Uniform Resource Locator (URL) that you need to enter when accessing Web pages using a Web browser.


Reference: Illustrated HTTP

— — the END — — –


Like this article friends, welcome to pay attention to the public number programmer xiao Grey, watch more exciting content