HTTP message Format
The HTTP message is divided into the request message and the response message, only the request message is sent, the response message will be.
The common message format is as follows:
Request message
A request message consists of four parts, namely:
- Request Line
- Request Header
- Blank Line
- Request Body
Request Line
The request line consists of three parts: the request method, the URL, and the protocol version.
GET /test/hi-there.txt HTTP/1.0
As shown above: The request line request indicates that the request method is Get,url Yes /test/hi-there.txt
, the protocol version is 1.0.
Request Header
The request header is composed of multiple key-value pairs, which are generally used to describe the client and the requirements of the server, which can be said that the request header is the most important part of the HTTP protocol, and many HTTP optimizations can begin with the request header.
An article will then be devoted to the request header.
Blank Line
A blank line, after the request header, consists of a carriage return and a newline character that is used to partition the request header and the request body.
Request Body
Parameters in the request body that typically store request methods (such as Post)
Response message
The response message is also made up of four parts, namely:
- Response Line
- Response header
- Blank Line
- Response body
Response Line
The response line consists of three parts: the protocol version, the status code, and the status description.
HTTP/1.0 200 OK
As shown above, the protocol version is version 1.0, the status code is 200, the status description is OK, from this can be seen, the server successfully returned information.
Response header
The response header is similar to the request header, which describes the server information and the response to the request header.
Blank Line
A blank line, after the response header, consists of a carriage return and a newline character that is used to partition the response header and response body.
Response body
The response body is the data returned by the server for HTTP requests, which can return different kinds of data depending on the HTTP request.
HTTP from getting started to being buried (5)--http message format