Next, I would like to review the TCP/IP protocol family related things, of course, most of these things were learned in college, but that sentence, the basis of things still need to review the back of the time. The next few blog is about the TCP/IP protocol family, this blog will be a simple chat about the TCP/IP protocol family, and then chat about the HTTP protocol, and then talk about the SSL http (that is, HTTPS) . Of course, the TCP/IP protocol family is a commonplace topic, the Internet on the content of the article on the catch a lot of it, but in view of its importance, it is necessary to summarize the system.
First, TCP/IP protocol group Brief
Before we talk about HTTP and HTTPS, let's briefly talk about the TCP/IP protocol family . TCP/IP refers not only to the two Protocols of TCP and IPs, but to the various protocols associated with them. For example, HTTP, FTP, DNS, TCP, UDP, IP, SNMP and so on are all part of the TCP/IP protocol family category.
Layering of 1.TCP/IP protocols
TCP/IP protocol family is hierarchical management , can be divided into 7 layers (Application layer, presentation layer, session layer, Transport layer, network layer, data link layer, physical layer, can be credited as: should be the table will be transmitted network number ), this blog we use tcp/ Four tiers of IP protocol families (application layer, Transport layer, network layer, link layer). Below is a brief description of each layer in layer four:
-
Application Layer : This layer is a user-oriented layer, that is, the user can directly manipulate the layer, which determines the user to provide application services when the communication activities. The HTTP (Hypertext Transfer Protocol: Hypertext Transfer Protocol) you want to talk about in this blog is located at that level. The FTP that we use frequently (the file Transfer Protocol: Files Transfer Protocol) and DNS (domain Name System: DomainName) are located at that level. FTP is simply used for file transfer. DNS is responsible for domain name resolution, through the DNS can be the domain name (such as: www.cnblogs.com) and IP address (201.33.xx.09) to convert each other . in layer 7, the layer is divided into: Application layer, presentation layer, and Session layer .
-
Transport Layer : Below the application layer is the transport layer, and the application layer Hu delivers the data to the transport layer for transmission. The TCP (transmission Control Prococol: Transmission protocol) and UDP (user Data Protocol: Subscriber protocol) are located at this level, of course, the name is known, This layer is used to provide direct data transfer between two computers that are in a network connection. TCP establishes a connection that requires three handshakes to confirm the connection, while UDP does not have a three-time handshake process . will be introduced later.
-
Network layer : Below the transport layer is the network layer, which is used by the network layer to process packets flowing over the network, and IP (Internet Protocol: Internetwork Protocol) is located on this layer . This layer is responsible for selecting a transmission line in many network lines. Of course, the process of selecting a transmission line requires IP address and MAC address support.
-
link Layer : In the 7 layer protocol, the link layer is divided into the data link layer and the physical layer . This part is mainly used to deal with the hardware part of the network, we often say the NIC (Net work card), that is, the network card is located in this part, of course, fiber is also part of the link layer.
In the TCP/IP protocol family, each time directly in the transmission of data collaboration, as well as the interaction process, or refer to the book "Graphical http" a picture to explain it. Is the way the four-layer protocol works during data transfer. The following picture is quite straightforward. On the sending side is the application layer----the link layer in this direction of the packet process , not passing through the layer will increase the head of the layer. The receiving end is the process of unpacking from the link layer to the application layer , and each passing layer will remove the corresponding header.
2. Three handshake of TCP protocol
Before we talk about the HTTP protocol, let's briefly talk about the TCP three handshake process, in the following blog we will be on the TCP and IP protocol details, this blog will be a simple chat on the basis of the HTTP protocol.
The TCP protocol is located in the transport layer, and in order to ensure the reliability of the transmission, the TCP protocol requires three handshake (three-way handshaking) when establishing the connection. The diagram below is the process of three handshake when the TCP protocol establishes a connection.
-
First handshake : The sending side sends a packet with a SYN (Synchronize) flag to the receiving end, which is used to ask the receiving side if it can receive it. If you can, do a second handshake.
-
Second Handshake : Receive end back to send a packet with syn/ack (acknowledgement) , to the sending side said, I received you sent me a SYN flag, I will send you an ACK flag, you can receive it? If the sender receives the syn/ack packet, it can confirm that the receiving side received the SYN that was sent, and then the third handshake.
-
Third handshake : The sender sends a packet with an ACK flag to the receiving end, telling the receiver that I can receive the syn/ack flag you sent me. If the receiver receives this ACK flag from the client, it means that the three handshake is complete and the connection is established to begin transmitting the data.
Second, HTTP message structure
The HTTP protocol is the full name of hypertext Transfer Protocol, the Hypertext Transfer Protocol, the user client and the server before the communication, the current widely used version of http/1.1. The protocol is essentially a specification, and the " interface-oriented " programming we've mentioned before is actually " protocol-oriented " programming. We define the protocol of the class first, that is, the interface, and the related classes follow the protocol, so that we can standardize the way these classes are called. The HTTP protocol is the protocol that regulates the communication between the client and the server. In other words, all the clients or servers follow the HTTP protocol, which means that the interface that transmits the data is always there, and it can be connected to the pipeline so that it can be transferred.
These protocols are interfaces, have a common communication protocol, and can communicate with each other on multiple ends . The same protocol is used to facilitate communication between all devices. The role of the HTTP protocol is as follows.
The function of HTTP protocol is to standardize the content of communication, and it can be divided into request message and Response message in HTTP protocol . As the name implies, the request message is the information sent by the requester, and the response message is the content of the response received upon request. Next we'll look at the overall structure of the request message and the response message.
1. Request message Structure
Below is the overall structure of the request message. The request message is mainly divided into two major parts, one is the request Headers and the other is the request body. Between the two is separated by a blank line. In the request header is divided into the request line, the Request header field, the General header field and the Entity header field, which will be described in detail later. Below is the structure of the request message.
This is the request Headerswhen requesting a page in the blog park. The first "GET" in the request line is the currently requested method, which is described later. The middle is the path to the requested resource, and the last http/1.1 is the current usage request protocol and its version. These are the request headers, which will be explained later in the general request header. The request body is the data that you transmit to the server, such as form form, God horse.
2. Response message (Response message) structure
After talking about the request message, we will talk about the response message, the structure of the response message is similar to the structure of the request message, and also divided into the message header and newspaper style. Below is the structure diagram of the response message. The response header (Response Headers) is divided into the status line, the response header field, the General header field, the Entity Header field, and so on. The response head is split with a blank line in the middle of the response body.
Below is the response header after the above request message is issued, the response body is for the HTML and other front-end resources . In the response header, the first line is the status line,"http/1.1" represents the 1.1 version of the HTTP protocol used , status 200 indicates a successful response , and "OK" is the state reason phrase. Common status, which is described in more detail later.
Third, HTTP request method and response status code
The "GET" mentioned above in the description request message is the request method, and the "200" status code mentioned in the response message is the response status code to be chatted later. The request method and the response status code are more important in the HTTP protocol. Before we developed the server side using the perfect framework , we talked about get, POST, put, and delete in the request method, and these four methods can be used in conjunction with rest . This section is a request method that is discussed in terms of the HTTP protocol, so it is slightly different from the previous one. In this section, let's talk about the HTTP protocol's request method and the response status code.
1. Request method
The next thing we want to talk about is the get, POST, PUT, HEAD, DELETE, OPTIONS, TRACE, CONNECT. Of course, the above method is based on http/1.1 , http/1.0 unique method will not say.
-
Get----Get resources
- The Get method is typically used to fetch resources from the server. After the server has received a GET request, it will understand that the client is going to get the appropriate resources from the server side and then return the required resources to the client based on the corresponding parameters in the request packet. Using the Get mode request, the transmitted parameters are stitched on the URI.
-
POST----Data Submission
- The Post method is generally used for form submission, which plugs the client's data into the request body and sends it to the server side.
-
PUT----Upload Files
- Put method is mainly used to upload files, the contents of the file into the request style, transfer to the server. Because the http/1.1 put method itself does not have a validation mechanism , so anyone can upload files, there is security, so when uploading files is not recommended to use. But before we designed the interface to use the rest standard, we could use put to update the content accordingly .
-
Head----Get the response message header
- When a head request is received by the response side, only the corresponding response header is returned and the response body is not returned.
-
Delete----deleting files
- Delete is used to delete the resource specified by the URI, which, like put, is self-contained without a validation mechanism, but can be used in the rest standard to delete the corresponding API.
-
Options----Query support methods
- The options method is used to query the server to respond to those request methods, and the return content is the method supported by the response side.
-
T RACE----Tracking Path
- The trace method tracks the proxy path through which the request passes, filling in numbers for the Max-forwards header field when the request is sent, and max-forwards the value of each broker-brokered transfer until the max-forwards is zero. will not return 200. Because this method is easy to cause XST (cross-site tracing, cross-site tracking) attacks , it is not commonly used.
-
Connect----require a tunneling protocol for proxy Connection
-
The Connect method requires a tunnel to be established when communicating with a proxy server to enable TCP communication with the tunneling protocol. The main use of SSL (secure Sockets layer) and TLS (Transport Layer Security, transport Security Layer) protocol to encrypt the communication content after the network tunnel transmission.
2. Response Status Code
After talking about the request method, let's talk about the HTTP protocol response status code. As the name implies, the response status code is used to flag the HTTP response status, the response status is composed of the response status code and the response reason phrase, of course, there are many status code, this section will pick out the common status code to discuss. Below are some of the categories that response status codes can be divided into:
- 1xx----Informational (Informational status code), indicating that the accepted request is being processed.
- 2xx----Success (successful), indicating that the request was processed properly.
- 3xx----Redirection (redirected), which means that the request is being redirected, except for 304 of these, of course.
- 4xx----Client Error, the server cannot process the request.
- 5xx----Server error (server fault), the server has encountered an error while processing the request.
Above is the overall classification of the response status code, followed by some common response status code.
(01), KOK : Indicates that the server correctly handles the request sent by the client.
(02),204 No Content : Indicates that the server handles the request correctly, but there is no message entity to return.
(03),206 Partial content : Indicates that the service side correctly handles the client's scope request and returns the entity content within that specified range according to the request scope.
(04),301 Moved permanently: Permanent Redirect, if the previous URI was saved to a bookmark, update the URI in the bookmark.
(05),302 Found: Temporary redirection, the redirect does not change the contents of the bookmark.
(06),303See other: Temporary redirect, same as 302 function, but 303 state clearly indicates that the client should use the Get method to obtain the resource.
(07),304 not Modified: The resource is not changed, the status code is not related to redirection, when the status code is returned, tells the client that the requested resource is not updated, the response style does not return the requested content.
(08),the "Bad Request": Error requests, indicating that the request message contains a syntax error.
(09),401 Unauthorized: The request is not authenticated, indicating that this send request requires the client to do HTTP authentication (mentioned later).
(10),404 Not Found: the corresponding resource could not be found, indicating that the server could not find the resource requested by the client.
(11),InternalServer error: Server internal errors, indicating that the server has encountered an error while processing the request, an exception occurred.
(12),503 Service Unavailable: Services are not available, indicating that the server is in a down state, unable to process the request from the client.
TCP/IP protocol Family (i) HTTP introduction, request method and response status code