1. Message stream
An HTTP packet is a data block sent between HTTP applications. These data blocks start with metadata in the form of text, which describes the content and meaning of the message, followed by the optional data section. We can compare a message stream to a flow of water. For water, the packet flow always goes down. Whether from the client to the server or from the server to the client, the end that receives the packet will always be downstream.
2. Composition of HTTP packets.
Including the start line, header, and subject. The start line and the header are ASCII text separated by rows. Each line ends with a line ending sequence consisting of two characters (CRLF)
2.1 starting line
The request line contains the request method, request URL, and HTTP Version. The response line contains an HTTP version, a digital status code, and a reason phrase.
2.1.1. Methods
What is the newspaper server doing. There are 7 common HTTP methods:
Get: Get a document from the server.
Head: obtains the document header from the server only.
Post: send the data to be processed to the server
Put: stores the Request body on the server.
Trace: traces messages that may be sent to the server through the proxy server.
Options: determines which methods can be executed on the server
Delete: delete a document from the server.
Note: All objects except post and put are excluded. Not all servers support these seven methods. In addition, some servers may have their own request methods.
The get and head methods are considered as safe methods, which means that HTTP requests using both methods do not produce any action. In my understanding, this means that the server will not execute an action because of these two methods. For example, if a POST request is used, the server will execute an action for the user. For example, if the user name and password are sent during login, the server will perform a match in the database, then return the result to the user.
Usually, post is used to support HTML forms. The data filled in the form will be sent to the server, and then the server will send it to the desired place, for example, to a Server Gateway Program, and then the program will process it.
When a client initiates a request, the request may pass through the firewall, proxy, gateway, or other applications. Each intermediate node may modify the original HTTP request. The trace method allows the client to check what the request looks like when it finally sends the request to the server. This reminds me of China's great firewall-gFW. When accessing a foreign website, the message may be modified when it passes through gFW. Therefore, the server returns a 404 error response message...
The delete method requires the server to delete the resource specified by the request URL, but the client application cannot guarantee that the deletion operation will be executed. The HTTP specification allows the server to cancel the request without notifying the client.
2.1.2. Status Code
Tell the client what happened. There are 5 categories.
100 ~ 199 -- Information Status Code. The purpose is to optimize the situation: the HTTP client application has an entity to be sent to the server, but you want to check whether the server will receive the entity before sending it.
200 ~ 299 -- Success status code
For more information about the code, see p64.
300 ~ 399 -- redirect status code
Return an optional location header to tell the client that the resource has been removed and provide an address. Generally, the browser directly redirects to the address without interrupting the user. See P65-67 for details
400 ~ 499 -- client error status code
If a client sends something that cannot be processed by the server, such as a request message in incorrect format or a nonexistent URL. This makes me feel that the GFW in China has changed the URL during request message transmission, leading to the failure of server processing.
500 ~ 599 -- server error status code
Look at P69-70 in detail
2.2 first
Is a list of some name/value pairs. It can be divided into common headers, request headers, response headers, entity headers, and extension headers.
The first detailed information can read the P71-76
This article from the "Lotus miss" blog, please be sure to keep this source http://liandesinian.blog.51cto.com/7737219/1557537
Chapter 2 HTTP packets