One, foreword
As a front-end development engineer, I can’t deal with the back end without HTTP protocol. HTTP belongs to the application layer in TCP/IP.
Second, the HTTP
HTTP is divided into request packets and response packets. The browser sends request packets and the server responds response packets
The request message
GET /index.html HTTP / 1.1
Host: xx.xx.xxx.xx
Connection: keep-alive
Cache-Control: max-age=0
User-Agent: Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/ 537.36EDG /92.0.902.67Accept: text/html,application/xhtml+xml,application/xml; Q = 0.9, image/webp image/apng, * / *; Q = 0.8, application/signed - exchange; v=b3; Q = 0.9Referer: http://47.98.159.95/my_blog/tag/HTTP/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh; Q = 0.9, en. Q = 0.8, en - GB; Q = 0.7, en - US; Q = 0.6, af. Q = 0.5If-None-Match: W/"6e02-176c127fcc0"
If-Modified-Since: Sat, 02 Jan 2021 03:33:12 GMT
Copy the code
The response message
HTTP / 1.1 200 OK
Server: Nginx / 1.10.3 (Ubuntu)Date: Sun, 15 Aug 2021 05:21:57 GMT
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Sat, 02 Jan 2021 03:33:12 GMT
Content-Type: text/html; charset=UTF-8
ETag: W/"6e02-176c127fcc0"
vary: Accept-Encoding
Content-Encoding: gzip
Copy the code
How to understand HTTP status codes?
The RFC defines HTTP status codes as three digits, which are divided into five categories:
- 1XX: This type of status code indicates that the request has been accepted and needs to be processed.
- 2xx: indicates that the request is successfully received, understood, and accepted by the server.
- 3XX: This type of status code indicates that the client needs to take further action to complete the request. Typically, these status codes are used for redirection, and subsequent request addresses (redirect targets) are specified in the Location field of this response.
- 4xx: The request packet is incorrect.
- 5xx: An error occurs on the server.
HTTP GET and POST request methods are different
- Generally, Search is used for GET and Request Body is used for POST
- The length of the GET URL is generally 2KB, and the length of the POST URL is unlimited
- GET requires only one message, and POST requires more than two
- GET is idempotent, POST is not idempotent
- Semantically GET is to GET data, and POST is to submit data
Difference between HTTP and HTTPS
- HTTP is a hypertext transmission protocol, and information is transmitted in plain text. HTTPS is a secure SSL encryption transmission protocol.
- HTTP and HTTPS use completely different connections and use different ports, the former 80 and the latter 443.
- HTTP connections are simple and stateless. HTTPS is a network protocol that uses SSL and HTTP to encrypt transmission and authenticate identity. It is more secure than HTTP. Stateless means that packets are sent, transmitted, and received independently of each other. Connectionless means that neither party maintains any information about the other for long.
TCP/IP protocol family
The TCP/IP protocol family is divided into four layers, because the two core protocols TCP/IP are the earliest standards passed in the family, so it is called TCP/IP protocol family, which is a simplified seven-layer OSI model
Application layer – Application layer
Provide application-specific protocols such as HTTP,FTP, and IMAP;
Transport layer – Transport layer
Applications that send packets to computers using specific port numbers TCP, UDP
Network layer – Internet Layer
Packets are sent to specific computers using IP addresses
- The Internet Protocol (IP) defines an address, which is called an IP address.
- Subnet mask
- Internet Control Message Protocol (ICMP) checks whether an IP packet is successfully sent to the destination address, and notifies the specific reason why an IP packet is discarded during sending. For example, we often use the ping command, which is a typical specific application of ICMP.
- ARP, which works at the link layer but belongs to the network layer, is a network transmission protocol to find the address of the data link layer by resolving the address of the network layer.
Link layer – Network Access (link) Layer
To exchange binary data packets with network signals such as Ethernet, Wi-Fi, MPLS, etc.
- Ethernet protocol determines the grouping mode of 0 and 1 electrical signals. A frame has a minimum of 64 bytes and a maximum of 1518 bytes. Its tag header is fixed at 18 bytes.
Three, extension,
TCP three-way handshake:
When establishing a TCP connection, the three-way handshake prevents the establishment of a historical connection, reduces unnecessary resource costs on both sides, and helps both sides initialize serial numbers synchronously. Serial numbers ensure that data packets are not repeated, discarded, and transmitted in sequence.
Reasons not to use “two handshakes” and “four handshakes” :
“Two-handshake” : it cannot prevent the establishment of a historical connection, resulting in a waste of resources on both sides, and cannot reliably synchronize the serial numbers of both sides.
“Four handshakes” : Three handshakes are the minimum number of reliable connections theoretically established, so there is no need to use more communications.
TCP’s four waves:
Why do you need four waves
The TCP connection is a full-duplex network protocol that allows the two communicating parties to send and receive data at the same time and the connection in the sending and receiving directions to be closed independently. In this case, the FIN sends data from the client to the server and closes the connection, but the server does not send data to the client. Therefore, four handshakes are required to close a TCP connection, and two handshakes are required to close a connection in one direction each time
Reference: www.cnblogs.com/xiaolincodi…