Request Method

Eight methods
GET
send a "display" request to the specified resource. Using the GET method should only be used to read data, and should not be used in operations that produce "side effects", such as in web applications. One of the reasons is that GET may be randomly accessed by web spiders. See safety method

The HEAD
method is the same as the GET method, which sends a request for a specified resource to the server. It's just that the server will not return the text part of the resource. Its advantage is that this method can be used to obtain "information about the resource" (meta information or metadata) without having to transmit all the content.

POST
submits data to the specified resource and requests the server for processing (such as submitting a form or uploading a file). The data is included in the request text. This request may create new resources or modify existing resources, or both.

PUT
uploads its latest content to the specified resource location.

DELETE
requests the server to delete the resource identified by the Request-URI.

TRACE
echoes the request received by the server, mainly for testing or diagnosis.

The OPTIONS
method enables the server to return all HTTP request methods supported by the resource. Use'*' to replace the resource name and send an OPTIONS request to the Web server to test whether the server function is working properly.

The CONNECT
HTTP/1.1 protocol is reserved for proxy servers that can change the connection to a pipe mode. Usually used for SSL encrypted server links (via non-encrypted HTTP proxy server).
The method name is case sensitive. When the resource for a request does not support the corresponding request method, the server should return status code 405 (Method Not Allowed). When the server does not recognize or does not support the corresponding request method, it should return status code 501 (Not Allowed). Implemented).

The HTTP server should at least implement the GET and HEAD methods, other methods are optional. Of course, the implementations supported by all methods should conform to the respective semantic definitions of the following methods. In addition, in addition to the above methods, specific HTTP servers can also extend custom methods. E.g:

PATCH (the method specified by RFC 5789) is
used to apply partial modifications to resources.

Security methods
For the GET and HEAD methods, these requests should have no other meaning except to obtain resource information. In other words, these methods should be considered "safe". The client may use other "non-secure" methods, such as POST, PUT, and DELETE, and should inform the client of possible consequences (such as a button-controlled fund transaction) or request in a special way (usually buttons rather than hyperlinks) The operation of may be unsafe (for example, a file will be uploaded or deleted).

However, it cannot be taken for granted that the server will not produce any side effects when processing a GET request. In fact, many dynamic resources will take this as their characteristic. The important difference here is that the user did not request this side effect, so the user should not be held responsible for these side effects.

Side effects
If the side effects of several requests are the same as or no side effects at all without considering issues such as errors or expiration, then these request methods can be regarded as "idempotence". GET, HEAD, PUT, and DELETE methods all have such idempotent properties. Also, according to the protocol, OPTIONS and TRACE should not have side effects, so they are of course idempotent.

If the result of a request sequence composed of several requests does not change after repeated execution of the request sequence or any one or more of the requests, the request sequence is "idempotent." However, it may appear that a request sequence composed of several requests is "non-idempotent", even if all the request methods executed in this request sequence are idempotent. For example, the result of this request sequence depends on a variable that will be modified during the next execution of this sequence.

Guess you like

Origin blog.csdn.net/qq_41411324/article/details/111253250