Summary of HTTP protocol: message structure, common status codes

1. Position in the TCP/IP protocol suite

Located at the application layer of the four-layer protocol. Implementation of TCP protocol based on the transport layer.

2. Request message structure

Including the message header, blank line, and message body 3 parts.

Message header: the
first line: request line, request method, request path, HTTP version.
Subsequent headers: including request header fields, general header fields, and entity header fields

Blank line:

Message body:
the data sent to the server. Such as the various parameters in the get request. The parameters in the post request.

3. Response message structure

It also includes three parts: message header, blank line, and message body.

Message header: the
first line: the status line, including the HTTP version status code reason phrase.
Followed by the header fields: response header field, general header field, entity header field

Message body: the response body returned by the server. Such as the HTTM page.

4. Common status codes

(1) 2xx

The status code at the beginning of 2 indicates success

200 OK

Processed normally and returned

204 No Content

It was processed normally, but there is no body in the response.
It is used when data needs to be sent from the client to the server but no response content is required.

206 Partial Content

The client made a range request, and the server returned normally. Specify the range through Content-Range when requesting.

(2)3xx

Redirect related

301 Moved Permanently

Permanent redirection. Indicates that the requested resource has been permanently assigned a new URI, and the new URI should be used in the future.
Use the Location header field to indicate the new URI address. The browser will request the URI again.

302 Found

Temporary redirect, hope that the user will use the newly assigned URI this time.
Very similar to 301, the browser will also re-request based on the Location field.
It is often used for page jump in actual development.

303 See Other

It has the same function as 302, except that it clearly indicates that the client should use a get request.

304 Not Modified

It has nothing to do with redirection. Indicates that the resource has not changed, and the client's unexpired cache can be used directly. It is possible to return this status code when requesting with conditions.

(4)4xx

Client error

400 Bad Request

There is a syntax error in the request. Such as the problem of parameter splicing.

401 Unauthorized

not certified

403

No Access

404 Not Found

(5)5xx

Server Error

500

Server internal error

503

service is not available

5. The role of the host header

Distinguish between different hosts. Some servers run multiple websites, each with a different domain name. If you do not specify a domain name when receiving a request, you cannot know which website is required to respond.

Guess you like

Origin blog.csdn.net/vxzhg/article/details/105276930