HTTP protocol is located in the application layer of the Protocol, we are in the daily Web page, such as in the navigation site request Baidu home page, will first through the HTTP protocol to do a similar coding work, sent to Baidu Server, Then in the Baidu Server response request to the corresponding content through the HTTP protocol to do a similar to the decoding work, so that the browser can understand the data, and then show us the Baidu home page.
This is equivalent to a specification, the transmission of data in the network under the application of the various layers (transport layer, application layer) to complete, in the TCP/IP protocol received data, we are not directly used and browsing, we need to first through a specification to comb, that is, decoding, a browser support format, To be used by us.
In web development, it is important to familiarize yourself with the message structure in the HTTP protocol, for example, if you are unfamiliar with HTTP messages, you will get into a httpservletrequest when using many methods.
HTTP messages are divided into request messages and response messages.
Requesting message (Request message)
The request message is divided into three parts: the first line, the request header, the request body.
The first line includes: request type, url,http version.
The request header holds the properties of some key-value pairs.
The request body holds specific content, typically a parameter of post type.
The following is a brief description of each part:
1, Method: The client wants the server to perform the action on the resource, is a separate word, for example, GET, post or head
2. Request URL (Request-url): To directly chat with the server, as long as the request URL is the absolute path of the resource can be, the server can assume that it is the URL of the host/port
3, Version: The HTTP version used by the message. Its format:http/< major version number >.< minor version number >
4. Status code (STATUS-CODE): The status code is a three-digit number that describes what happened during the request. The first digit of each status code is used to describe the general category of State (for example, "Success", "error", etc.)
5. Reason phrase (reason-phrase): A readable version of the numeric status code that contains all the text before the line termination sequence. The reason phrase is only meaningful to humans, so although the response line http/1.0 not OK and http/1.0, the meaning of the phrase is different, but will also be treated as a success indicator
6, head (header): can have 0 or more heads, each header contains a name, followed by a colon (:), then an optional space, followed by a value, and finally a CRLF header is a blank line (CRLF) end, Represents the end of the head list and the beginning of the entity body part
7, the body of the entity (Entity-body): The body of the entity contains a data block composed of arbitrary data, not all the messages contain the body of the entity, and sometimes the message is just a CRLF end.
Response message (Response message)
The response message is also composed of three parts, the first line, the response head, the response body.
The first line is divided into message protocol and version, response code and status description
Status code
1XX: Informational Status code
2XX: Success Status Code, 200 indicates success
3XX: Redirect Status code
4XX: Client Error status Code, 404 indicates no requested resource found
5XX: Server-side error status code, 500 indicates internal error
For response message response header properties, please refer to the above table link.
It should be mentioned that we can add the response header property by HttpServletResponse's SetHeader () method.
Reprinted from: https://www.cnblogs.com/fingerboy/p/6245882.html
HTTP protocol--Request message and response message