Http(Hypertext Transfer Protocol)
HTTP protocol (HyperText Transfer Protocol, Hypertext Transfer Protocol) is used to transfer files from the WWW A transfer protocol used by servers to transmit hypertext to local browsers. It can make the browser more efficient and reduce network transmission. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the document is transmitted and which part of the content is displayed first (such as text before graphics), etc.
The information used for http protocol interaction is called a http message. The http message from the requesting end (client) is called a request message, and the
http
message from the responding end (server) is called a response message. The request message consists of request method
, request
URI, protocol version, header field (optional), content entity (optional) The response message consists of protocol version, status code
, reason phrase, header field (optional), and entity body
In each message, the request URI, protocol version, status code, reason phrase, header field belongs to the message header, then a blank line, and the rest is the message body.
There are 4 types of header fields: request header field, response header field, general header field, entity header field, general header and entity header are the request message and Both response messages have them, while request headers are only available in request messages, and response headers are only available in response messages.
Message is the basic unit in http communication, consisting of 8 bits Composed of byte stream, transmitted through http communication.
The entity is transmitted as the payload data (supplementary item) of the request and response, and its content consists of the entity header and the entity body
Generally, the message body is equal to the entity body . Only when the encoding operation is performed during transmission and the content of the entity body changes, will it be inconsistent with the message body.
http1.0 and http1.1Supported methods
Method |
Description |
Support httpProtocol version |
##GET | Get the resource identified by URI |
1.0,1.1 |
##POST |
##Transmission Entity Body
|
1.0,1.1
|
##PUT | Transfer files( Without verification mechanism) | 1.0,1.1
|
##HEAD
Get the message header |
1.0,1.1 |
|
##DELETE
##Delete file | (without verification Mechanism)##1.0,1.1 |
OPTIONS |
##Ask for support methods |
1.1 |
TRACE |
Trace path |
##1.1
|
##CONNECT
| Requires tunneling protocol to connect to proxy
##1.1 |
|
LINK
Establish connections with resources |
1.0 |
|
UNLINK
Disconnect link relationship |
##1.0 |
|
##http
Status code
##Status code
Category |
Reason Phrase |
1XX |
Informational (Informational status code) | The received request is being processed |
##2XX |
Success (success status code)
|
The request has been processed normally. |
##3XX |
##Redirection (Redirect status code) |
Additional operations required to complete the request |
4XX
|
Client Error(Client error status code)
|
The server cannot process the request
| ##5XX
| Server Error
(Server error status code)
| Server processing request error Commonly used status codes in
14
##200 OK |
Indicates that the request from the client is processed normally on the server side |
204 No Content |
means that the request received by the server has been processed successfully, but the response message returned does not contain the entity body part |
206 Partial Content |
Indicates that the client made a range request and the server successfully executed it Partial GETRequest |
##301 Moved Permaently
|
A permanent redirect, indicating that the requested resource has been assigned a new URI and that the # that the resource now refers to should be used in the future. ##URI
|
##302 Found
Temporary redirection means that the requested resource has been assigned a new | URI, and we hope that the user can use the new URI to access ## this time. | 303 See Other
indicates that the request corresponds to There is another URI |
for the resource. You should use the GET method to obtain the requested resource
| 304 Not Mod ified## indicates that the client sends conditions When requesting, the server allows the request to access the resource, but if the request does not meet the conditions, it will directly return 304 Not Modified | (the server-side resource is changed, and the client's unexpired resource can be directly used. Body part)
307 Temporary Redirect |
Temporary redirection, has the same meaning as 302 |
#400 Bad Request |
indicates that there is a syntax error in the request message. The server cannot recognize the request |
401 Unauthorized |
## means The request sent needs to pass the authentication information of http authentication. If a request has been made before, it means that the user authentication failed
|
##403 Forbidden |
indicates that access to the requested resource was denied by the server. No permission to access
|
404 Not Found |
indicates the server The requested resource cannot be found, that is, there is no such resource
|
500 Internal Server Error |
Indicates that an error occurred on the server side when executing the request. It may also be that the web application has a bug |
or some temporary Fault 503 Service Unavailable
|
means The server is temporarily overloaded or is undergoing downtime for maintenance, and is now unable to process requests
|
httpCommon header field
Common header field name |
Description |
##Cache -Control |
##Control the behavior of cache
|
##Connection
| Manage hop-by-hop headers and persistent connections
|
Date ##Date and time when the message was created |
|
Pragma
##Message command |
| Trailer
List of headers at the end of the message |
| Transfer-Encoding
Specify the transfer encoding method of the message body |
| Upgrade
Upgrade to other protocols and check whether higher version protocols can be used for communication |
| Via
##Related information about the proxy server, tracking the client and server The transmission path between request and response messages |
Warning |
Error notifications, usually inform users of some warnings about cache-related issues |
http1.1 Warning code (Warning has seven types)
Warning code |
Warning content |
Description |
110 |
Response is stale( Response has expired) |
The proxy returns expired resources |
##111 |
Revalidation failed(Revalidation failed) |
The agent failed to verify the validity of the resource (the server cannot be reached, etc.) |
112 |
Disconnection operation( Disconnect operation) |
# #Agent and Internet link are deliberately cut off
|
##113
| Heuristic expiration(Heuristic expiration ) ##The response period exceeds | 24 hours (when the effective cache setting time is greater than 24 hours)
|
199
##Miscellaneous warning( Miscellaneous warning |
) Any warning content
|
##214 |
Tansformation applied(Transformation used | )The agent encodes the content or media type etc. |
299 |
Miscellaneous persistent warning(persistent miscellaneous warning | )Any warning content |
httpRequest header field
Request header field |
Description |
##Accept |
The media types that the user agent can handle and the relative priority of the media types |
Accept-Charset |
Preferred Character set, the character set supported by the user agent And relative priority |
##Accept-Encoding
|
takes precedence Content encoding, user agent supported content encoding and priority order
|
##Accept-Lang uage
| Prioritized languages, the natural languages that the user agent can handle and the relative priority of the set of natural languages
|
Authorization
| WebAuthentication information
|
Expect
| Expect specific behavior from the server
|
From
| User’s email address
|
Host
| The server where the requested resource is located (host name and port number)
|
If-Match
| Compares with the entity tag (ETag ), if If they are the same, execute the request, otherwise return 412status code
|
##If -Modefied-Since
If | If-Modefied-Since field value is earlier than the resource's update time, you want to process the request, otherwise return 304status code | ##If-None-Match
Compare entity tags (the opposite of If-Match |
) ##If- | Range
Resources Send a range request for entity Byte | when it is not updated. If the If-Range field value is consistent with the ETag value or time of the requested resource, it will be processed as a range request, otherwise it will be returned All resources##If-Unmodified-Since |
Compare the update time of resources (contrary to If-Modified-Since ) |
##Max-Forwards |
Maximum transmission hop-by-hop number (specifies the maximum number of servers that can be passed through in decimal form)
|
Proxy-Authorization |
The proxy server requires the client’s authentication information
|
Range |
Byte range request for entity
|
Referer |
To the original getter of URI in the request (the URI of the requested original resource) |
##TE |
Inform the server that the client can The transfer encoding method and relative priority of processing responses |
User-Agent |
httpClient program information |
## http Response header field
Response header field
| ##Description
|
Accept-Ranges
| Accept-Ranges Byte range request
|
Age
| Resource creation process The time, in seconds
|
##ETag
Resource The matching information can inform the client of the entity identification |
|
Location
Redirect the client to the specified | URI
| ##Proxy-Authenticate
Authentication information from the proxy server to the client |
##Retry-After |
Requirements for the timing of reinitiating the request |
Server |
http Installation | Information of the server ##Vary |
Proxy server cached management information |
WWW-Authenicate |
Server authentication information for the client |
httpEntity header field
Entity header field |
Description |
##Allow |
httpMethods supported by resources |
Content-Encoding
|
Encoding method applicable to entities |
Content-Language
|
The natural language of entities |
Content-Length |
The size of the entity (in bytes) |
Content-Location |
#Replace the URI | of the corresponding resource
Content-MD5 |
##Entity body message Summary
|
Content-Range
|
The position of the entity body Scope
|
Content-Type
|
Media of the entity body Type
|
Expires
|
The date and time when the entity body expires
|
Last-Modified
|
The date the resource was last modified time
|
|
|
|
|
The above is the detailed content of HTTP methods, status codes and components. For more information, please follow other related articles on the PHP Chinese website!