This sharing HTTP protocol, is divided into three parts, this is the second part, the main explanation of the request and response fields, as well as the status code.
A complete request and response with the http/1.1 version as an example
HTTP request information is made up of three parts
1. Request Method (Get/post),URI, Protocol /version
2. Request Header
3. Request Body
eg
Get/form.html http/1.1 (CRLF)
Accept:image/gif,image/x-xbitmap,image/jpeg,application/x-shockwave-flash,application/vnd.ms-excel,application /vnd.ms-powerpoint,application/msword,*/* (CRLF)
ACCEPT-LANGUAGE:ZH-CN (CRLF)
Accept-encoding:gzip,deflate (CRLF)
if-modified-since:wed,05 Jan 11:21:25 GMT (CRLF)
if-none-match:w/"80b1a4c018f3c41:8317" (CRLF)
user-agent:mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0) (CRLF)
Host:www.guet.edu.cn (CRLF)
Connection:keep-alive (CRLF)
(CRLF)
The first line is the request method get URL:form.html protocol version: http/1.1
Second line, accept: What data formats can be received by declaring
Third line accept-language: What languages can I claim to support?
Line four accept-encoding: declaring supported encoding formats
Line five if-modified-since: Declares the last modified time for this file
Line six if-none-match: used to determine whether the resource for the current request has changed
Line Seventh User-agent: User agent, store some browser information and system information
Line Eighth host: the server on which the requested resource resides
Line eighth Connection: Declaration is a persistent connection
CRLF carriage return to newline
--------------------------------------------------------------------------------------------------------------- -----------------------
Here is the usual request field explanation
Accept the media types that the user agent can handle
Accept-charset-Preferred Character Set
Accept-encoding-Priority content encoding
Accept-language Preferred Language (natural language)
Authorization Web authentication Information
Expect expecting specific behavior of the server
From user's e-mail address
Host requests the server on which the resource resides
If-match Comparing entity markers (ETAG)
If-modified-since update time for compare resources
If-none-match Comparing entity markers (as opposed to If-match)
A range request to send entity Byte when If-range resource is not updated
If-unmodified-since update time for compare resources (contrary to if-modified-since)
Max-forwards Maximum Transmission hop-on count
Proxy-authorization Proxy Server requires authentication information from the client
Byte range request for range entity
Referer the original acquisition of the URI in the request
Priority of TE transfer encoding
User-agent information for HTTP client programs
HTTP replies are similar to HTTP requests, andHTTP responses are made up of 3 parts, namely:
1, status line
2. Response header (Response header)
3. Response body
eg
http/1.1 OK
Server:nginx
Date:tue, 02:09:24 GMT
Content-type:application/json;charset=utf-8
Connection:keep-alive
Vary:accept-encoding
Access-control-allow-origin: *
Access-control-allow-headers:x-requested-with,access_token,access-token,content-type,multipart/form-data, application/x-www-form-urlencoded
Access-control-allow-methods:get,post,options
content-length:49
{"ResultCode": 1, "resultmsg": "Phone number not registered"}
First line : protocol version http/1.1 Status Code 200 status description OK
second line : informs the client about the HTTP server application installed on the current server. It contains the software app name, even the version number and the startup item at the time of installation
Third line: Response time
Line four: The media type of the entity body
Line five: declaring long connections
Line six: Control the cache management information
Line seventh: the declaration allows any
Line Eighth: declaration allows anyone to access
Line Nineth: Set the Allowed Access request method
Line tenth: indicate the body length
Blank line: Indicates end of response header
Response body
--------------------------------------------------------------------------------------------------------------- -------------------------
Here are some common response fields
whether the Accept-ranges accepts byte-range requests
Age calculates resource creation elapsed time
matching information for ETag resources
Location enables the client to redirect to the specified URI
proxy-authenticate Proxy Server Authentication information for the client
Retry-after The timing of the request to re-launch
installation information for server HTTP server
Vary Management information for proxy server caching
www-authenticate Server-to-client authentication information
Allow resources to support HTTP methods
content-encoding The encoding method that the entity body applies to
Natural language of content-language entity body
content-length the size of the entity body (units: bytes)
content-location A URI that replaces the corresponding resource
the report Digest of CONTENT-MD5 entity body
Content-range The position range of the entity body
content-type The media type of the entity body
Expires The date time that the entity principal expires
last-modified Last Modified date time of the resource
--------------------------------------------------------------------------------------------------------------- -------------------
Response Status Code explanation
The status code consists of three digits, the first number defines the category of the response, and there are five possible values:
1XX: Indication information--Indicates that the request has been received and continues processing
2XX: Success-Indicates that the request has been successfully received, understood, accepted
3XX: Redirect--further action is required to complete the request
4XX: Client Error--Request syntax error or request not implemented
5XX: Server-side error-the server failed to implement a legitimate request
A common status code explanation
Continue continued. The client should continue its request.
101 Switching Protocols switch protocols. The server switches the protocol based on the client's request. You can only switch to a more advanced protocol, for example, a new version of the protocol that switches to HTTP
A $ OK indicates that the request from the client is handled properly on the server side.
204 No content The status code indicates that the request received by the server has been processed successfully, but does not contain the body part of the entity in the returned response message. For example, when a request is processed from the browser and a 204 response is returned, the page displayed by the browser does not update
206 Partial Content The status code indicates that the client made a scope request, and the server successfully performed the GET request for this part.
301 Moved Permanently permanent redirect. The status code indicates that the requested resource has been assigned a new URI, and the URI that the resource now refers to should be used later. Like the request URI given below, when the specified resource path finally forgets to add a slash "/", a 301 status code will be generated
302 Found temporary redirection. The status code indicates that the requested resource has been assigned a new URI and that the user (this time) will be able to access it using the new URI.
303 See other The status code indicates that the requested resource should be obtained by using the Get method, because another URI exists for the resource that corresponds to the request. The 303 status code and 302 status code have the same function, but the 303 status code clearly indicates that the client should use the Get method to obtain the resource. when the 301,302,303 response status code returns, almost all browsers will change the post to get and delete the principal of the request message, and the request will be sent again automatically. the 301,302 standard is to prohibit the post method from being changed to a get method, but everyone does it in practice.
304 Not Modified This status code indicates that the server side allows requests to access resources but does not meet the conditions when the client sends a request with a condition. 304 When the status code returns, it does not contain any body parts of the response. 304 is divided in the 3XX category, but is not related to redirection.
307 Temporary Redirect temporary redirection. The status code has the same meaning as 302 found. 307 will follow the browser standard and will not change from post to get.
The status code indicates that there is a syntax error in the request message. When an error occurs, you need to modify the requested content and then relax the request again.
401 Unauthorized The status code indicates that the request sent requires authentication information that is authenticated by HTTP, and that if 1 of this request has been made before, the user authentication fails.
403 Forbidden The status code indicates that access to the requested resource was rejected by the server.
404 Not Found The status code indicates that the requested resource could not be found on the server. In addition, it can be used when the server denies the request and does not want to justify it.
Internal Server Error This status code indicates that the server side has encountered an error while executing the request.
503 Service unavailable This status code indicates that the server is temporarily over-loaded or is undergoing downtime maintenance and is now unable to process the request.
Weekly share of the two HTTP protocol (2)