The HTTP protocol belongs to the application layer of TCP/IP and is used for communication between the client and the server. The client requests access to resources such as text or images, and the server provides resource response. In the HTTP protocol, the client initiates the request first and the server does not respond before receiving the request. This chapter focuses on THE HTTP/1.1 version, which is somewhat different from HTTP/2.0. I will compare the differences between the two versions later.

##1 HTTP in TCP/IP

  • 1.1 DNS: belongs to the application layer. The domain name resolution system converts domain names into IP addresses. The underlying network layer is addressed by IP, so it does not recognize domain names.
  • 1.2 TCP: at the transport layer, it is responsible for end-to-end connection and provides reliable connection through three-way handshake.
  • 1.3 IP protocol: belongs to the network layer and is responsible for packaging the data to be transmitted from a host to the target IP host;

# # 2 HTTP request and response headers HTTP protocol through the client request and response from the server to establish the communication, so you must request and response information must be in accordance with the specific routines to, or the two sides will not know, for example, to call the Japanese first you have to make sure to use what kind of language to communicate, this example rather pale, But Who Care! ####2.1 Request Packet The format of a client request is called a request packet, which consists of the request method, URI, HTTP version number, request field (optional), and request content (optional).

So let’s talk about the components.

  • 2.1.1 Request method: First of all, your client needs the server to provide services, you must first let the server know what you want to do, whether it is to wash feet or massage or a dragon, different request intention price is different, the server will also be different. 2.1.1.1 GET Method: Obtain resources. 2.1.1.2 POST method: When obtaining resources, transport entities are added. GET can also be used, but GET is generally not used in this way. 2.1.1.3 PUT method: Transfer physical files. Generally not, because it is not secure, the method itself does not have security verification, resulting in anyone can send files to your server. 2.1.1.4 HEAD method: It is the same as GET to obtain resources, but only the response header is obtained, and the server does not return the packet body. 2.1.1.5 DELETE: Deletes a specified resource, which is the opposite of PUT. 2.1.1.6 OPTIONS: The method to obtain the URI supported by the server for the request; 2.1.1.7 TRACE: Tracing path, tracing the proxy server through which the request passes, which can be used to confirm the operations performed when the request passes through the proxy; 2.1.1.8 CONNECT: The tunnel protocol is used to CONNECT the agent and communicate with the agent.
  • 2.1.2 Uniform Resource Identifier (URI) URIs are used to identify resources, while URLS are used to identify Internet resources. URL is a narrow concept, and URI is a broad concept. Uris include URLS. No longer use URL, use URI, absolute URI format is
  • 2.1.3 HTTP protocol version used by the client. As the name implies, the HTTP protocol version number is HTTP/0.9(not as a standard when it appeared), HTTP/1.0(as a standard at the beginning), HTTP/1.1(the current popular version), and HTTP/2.0(the latest version and the rapidly popularized version).
  • 2.1.4 Request header Field Specifies the content or attributes of the request to be processed by the server. Some additional requirements can be added. There are too many fields in this field, which will be discussed later.
  • 2.1.5 Content Entity The client sends data content, such as the file and field attached by POST request, which is added here.

# # # 2.2 response message after receiving the client’s bosses request, the server will return the corresponding request information, namely the response message, response message including the HTTP protocol version on the server side, a status code, the cause of the said status code phrase, of the three state line, in addition to response to the first field, as well as the response body, whole structure besides the status line, The structure of other parts is similar to that of request packets.

There is an essential blank line between the packet body and the header field.

  • 2.2.1 Protocol Version Indicates the HTTP protocol version used by the server
  • 2.2.2 Status codes and Cause phrases: The status code is accompanied by a reason phrase describing the status code. It is by the status code that our client determines whether the request is successful or failed. The status code consists of three digits and is mainly divided into the following categories: 2.2.2.1 1xx Informational status code, 2.2.2.2 2xx request success status code, the request is normally processed, the commonly used is 200,204,206 2.2.2.3 3xx redirection status code, some additional operations need to be performed to complete the request, the commonly used is 301,302,303, 307 2.2.2.4 4xx client error status code: indicates that there is an error in the client’s request. The commonly used ones are 400,401,403,404. 2.2.2.5 5xx server error status code: indicates that an error occurs in the server’s processing. It’s convenient to turn it over later.
Status code The reason the phrase The reason the phrase
200 OK The request from the client is successfully processed. Procedure
204 No Content Successfully processing the request without returning the body content is typically used when the client sends information to the server without the server having to return new content
206 Partial Content The client makes a range request, a GET method that asks for a portion of the resource
301 Moved Permanently Permanent redirection. The requested resource has a new URI
302 Found Temporary redirection. The requested resource is temporarily replaced with a new URI
303 See Other The resource has another URI that explicitly requires the client to use the GET method to obtain the resource
304 Not Modified The server has found the resource, but it does not meet the client’s additional condition, because it has nothing to do with redirection
307 Temporary Redirect Temporary redirection, which stands for 302, meets specific browser requirements
400 Bad Request A syntax error occurred in the request packet. Procedure
401 Unauthorized You don’t have enough access to the request
403 Forbidden Server denied service, no why, just refused
404 Not Found The server could not find the requested resource. This excuse is also used when the server wants to politely reject you
500 Internal Server Error I don’t have to say anything. There’s a bug on the server
503 Service Unavailable Ask for an egg. The server is down

The header field of request message and response message has not been discussed in detail, because these fields are too many, depending on fate, and then code, as literacy.