[Posts] The method of HTTP request: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE method described HTTP request: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE described

The method of HTTP request: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE described

  The usual Rest development, use of all GET, POST, PUT, DELETE types of requests.

       But Rest supported request types than the previous four kinds, there are several other.

       Transfer from the following portion:  https://www.html.cn/archives/9341

 

https://www.cnblogs.com/lnlvinso/p/11000568.html

 

       

  Hypertext Transfer Protocol (HTTP, HyperText Transfer Protocol) is a stateless protocol, which is located in the OSI model transport layer. HTTP client needed to build the appropriate HTTP request method, and the HTTP server may respond differently depending on the HTTP request method.

  1. The method of HTTP request and HTTP version

  In the development process of HTTP, there have been many versions of HTTP, which most of the agreements are downward compatible. During HTTP request, the client tells the server when requesting the protocol version it uses, which makes the server using the same or an earlier version of the protocol to respond.

  HTTP/0.9

  This is the first large-scale use of HTTP version, is now obsolete. In this version, only GETone kind of request method, the HTTP communication did not specify a version number, does not support the request header information. This version does not support POSTother methods, so the ability to pass information to the client server is very limited. HTTP/0.9Requested is the following line:

  GET www.itbilu.com

  HTTP/1.0

  This version is the first version number specified in the HTTP communication protocol version HTTP/1.0is still being widely used, especially in the proxy server.

  HTTP/1.0GETSupport: POST, , HEADthree kinds of HTTP request methods.

  HTTP/1.1

  HTTP/1.1I am currently using version. The default version uses a persistent connection, and can work well with a proxy server. Also supports the pipe simultaneously send multiple requests, in order to reduce line load, increase the transmission speed.

  HTTP/1.1OPTIONSAdded: PUT, DELETE, TRACE, , CONNECTfive kinds of HTTP request methods.

  HTTP/2

  This version is the latest released version, in May this year (May 2015) to make HTTP standard officially released. HTTP/2By supporting multiple requests corresponding to a weight to reduce latency, the HTTP header field compression by protocol overhead to a minimum, while increasing the priority of the request and the server-side push support.

  2. HTTP request method described

  HTTP/1.1CCP protocol defines eight methods HTTP request, the HTTP request method is also called "requested operation", different methods provide for different ways of operation specified resource. The server will do different responses depending on the request method.

  GET

  GETRequest will 显示request the specified resource. General GETmethod should be used only for reading data, and should not be used to produce side effects 非幂等operation.

  GETThe method will request the specified page information, and returns the response body, GETit is considered to be unsafe method, because GETthe method can be any access network spiders.

  HEAD

  HEADMethod and GETmethod, are specified resource request to the server. However, the server response HEADdoes not return the contents of part of the resource request, namely: the response body. Under such circumstances, we can not transmit the entire contents, you can get the server's response headers. HEADThe method is often used by the client to view server performance.

  POST

  POSTSubmit a request to the designated resource data, the server processes the request, such as: Submit form data, file upload, etc., request data is contained in the request body. POSTThe method is 非幂等a method, since the request may create new resources and / or modify existing resources.

  PUT

  PUTRequests the body to upload their content to the latest specified resource location, PUTmethod is 幂等the method. The latest resource data transfer specified by this method the client to the server can replace the contents of the specified resource.

  DELETE

  DELETERequest for requesting the server to delete the requested URIresources identified (Uniform Resource Identifier uniform resource identifier). DELETEAfter the specified resource request is deleted, DELETEthe method also 幂等is.

  CONNECT

  CONNECTThe method is HTTP/1.1protocol reserved, the proxy server can be connected to the pipeline mode. Commonly used in SSL communication link and the non-encrypted encrypted HTTP proxy server.

  OPTIONS

  OPTIONSRequest HEADsimilar, it is generally used by the client to view server performance. This method will return all HTTP requests that the server supports the requested resource method will use '*' instead of the resource name, the server sends a OPTIONSrequest, you can test server functions are normal. JavaScript's XMLHttpRequest object CORSwhen cross-domain resource sharing, is to use the OPTIONSmethod to send sniffer request to determine whether there is access to the specified resource. allow

  TRACE

  TRACEEcho request message requesting the server which receives the HTTP request method is mainly used for test or diagnosis.

  HTTP/1.1After increasing method

  In the HTTP/1.1following standards, and gradually expand a number of ways. Which is in use more  PATCHmethods?:

  PATCH

  PATCHThe method appears later, in 2010, it is RFC 5789 is defined standard. PATCHRequest and PUTthe request is similar to, for updating the same resource. Both the following differences:

  • But PATCHthe general part of the resources for the update, and PUToverall resources for the general update.
  • When the resource does not exist, PATCHit creates a new resource, and PUTwill only have to update the resource.

 

       Security and Idempotence 

  These HTTP requests on a method used with two basic characteristics, i.e., "Security" and "idempotent."

       For the above seven HTTP methods, GET, HEAD and OPTIONS methods are considered safe because they are designed to achieve access to the data, does not have the "border effect." As for the other four HTTP methods, since they cause a change of server resources, so the method is considered to be unsafe.

  Idempotent (the Idempotent) is a mathematical concept, where one indicates a boundary and transmitting multiple requests effect induced is the same. In the case where speed is not fast enough, the client sends a request can not be immediately respond, because if not determine whether the request was successfully submitted, it is possible to send the same request again another, determining the second idempotent a request is valid.

  Above three secure HTTP method (GET, HEAD, and OPTIONS) are idempotent method. Since PATCH DELETE request and a specific operation of existing resources, so they are idempotent method. For PUT request, only in the case of a server will add the corresponding resource does not exist, otherwise only for modification operations, so it is also idempotent methods. As for the last POST, because it always add operation, if the server receives the same twice POST operations, will result in two identical resource is created, so this is a non-idempotent methods.

  When we were designing the Web API should try to determine the logic processing of the request of the HTTP method of idempotent type. Because PUT is a power and other methods, so carry the same resource PUT request should not cause the change of state resources, if we attach a self-growth in the resource counter indicates the number is modified, it actually undermines the idempotent type.

        

       Statelessness

  RESTful state as long as the maintenance of resources, without the need to maintain client state. For it is, each request is new, as it requires a corresponding operation for this request, information need not be recorded down to this request for subsequent processing from the same client requests.

  For these two characteristics described above, we RESTful, and they asked us to meet all these features do something, but it is only the stateless asked us what not to do, because HTTP itself is stateless. For example, a web page by obtaining records match the query call Paging Web API. In general, the page navigation has recorded the previous page and the next page of the "previous" and "next" link for presenting the current page. So now there are two ways to achieve return records up and down the page.

  • Web API will not only define actions based on the specific data query definition of the relevant page, but also define a separate operation for such a request "Previous" and "Next." Its own will on the page every time the returned data is saved locally according to the client Session ID, in order to be able to know specifically what the previous and next page.
  • Web API will define actions based on the specific data query definition of the relevant page, the current page number to return data from the client to maintain.

  The first looks like a very "smart", is actually a superfluous practice, because it undermines the stateless nature of the Web API. Design stateless Web API Web API not only make themselves look simple and refined, but also because of the deduction for the client's "affinity (Affinty)" so that we can effectively implement load balancing, because the only way the cluster each server for each client is equivalent.

  The usual Rest development, use of all GET, POST, PUT, DELETE types of requests.

       But Rest supported request types than the previous four kinds, there are several other.

       Transfer from the following portion:  https://www.html.cn/archives/9341

 

https://www.cnblogs.com/lnlvinso/p/11000568.html

 

       

  Hypertext Transfer Protocol (HTTP, HyperText Transfer Protocol) is a stateless protocol, which is located in the OSI model transport layer. HTTP client needed to build the appropriate HTTP request method, and the HTTP server may respond differently depending on the HTTP request method.

  1. The method of HTTP request and HTTP version

  In the development process of HTTP, there have been many versions of HTTP, which most of the agreements are downward compatible. During HTTP request, the client tells the server when requesting the protocol version it uses, which makes the server using the same or an earlier version of the protocol to respond.

  HTTP/0.9

  This is the first large-scale use of HTTP version, is now obsolete. In this version, only GETone kind of request method, the HTTP communication did not specify a version number, does not support the request header information. This version does not support POSTother methods, so the ability to pass information to the client server is very limited. HTTP/0.9Requested is the following line:

  GET www.itbilu.com

  HTTP/1.0

  This version is the first version number specified in the HTTP communication protocol version HTTP/1.0is still being widely used, especially in the proxy server.

  HTTP/1.0GETSupport: POST, , HEADthree kinds of HTTP request methods.

  HTTP/1.1

  HTTP/1.1I am currently using version. The default version uses a persistent connection, and can work well with a proxy server. Also supports the pipe simultaneously send multiple requests, in order to reduce line load, increase the transmission speed.

  HTTP/1.1OPTIONSAdded: PUT, DELETE, TRACE, , CONNECTfive kinds of HTTP request methods.

  HTTP/2

  This version is the latest released version, in May this year (May 2015) to make HTTP standard officially released. HTTP/2By supporting multiple requests corresponding to a weight to reduce latency, the HTTP header field compression by protocol overhead to a minimum, while increasing the priority of the request and the server-side push support.

  2. HTTP request method described

  HTTP/1.1CCP protocol defines eight methods HTTP request, the HTTP request method is also called "requested operation", different methods provide for different ways of operation specified resource. The server will do different responses depending on the request method.

  GET

  GETRequest will 显示request the specified resource. General GETmethod should be used only for reading data, and should not be used to produce side effects 非幂等operation.

  GETThe method will request the specified page information, and returns the response body, GETit is considered to be unsafe method, because GETthe method can be any access network spiders.

  HEAD

  HEADMethod and GETmethod, are specified resource request to the server. However, the server response HEADdoes not return the contents of part of the resource request, namely: the response body. Under such circumstances, we can not transmit the entire contents, you can get the server's response headers. HEADThe method is often used by the client to view server performance.

  POST

  POSTSubmit a request to the designated resource data, the server processes the request, such as: Submit form data, file upload, etc., request data is contained in the request body. POSTThe method is 非幂等a method, since the request may create new resources and / or modify existing resources.

  PUT

  PUTRequests the body to upload their content to the latest specified resource location, PUTmethod is 幂等the method. The latest resource data transfer specified by this method the client to the server can replace the contents of the specified resource.

  DELETE

  DELETERequest for requesting the server to delete the requested URIresources identified (Uniform Resource Identifier uniform resource identifier). DELETEAfter the specified resource request is deleted, DELETEthe method also 幂等is.

  CONNECT

  CONNECTThe method is HTTP/1.1protocol reserved, the proxy server can be connected to the pipeline mode. Commonly used in SSL communication link and the non-encrypted encrypted HTTP proxy server.

  OPTIONS

  OPTIONSRequest HEADsimilar, it is generally used by the client to view server performance. This method will return all HTTP requests that the server supports the requested resource method will use '*' instead of the resource name, the server sends a OPTIONSrequest, you can test server functions are normal. JavaScript's XMLHttpRequest object CORSwhen cross-domain resource sharing, is to use the OPTIONSmethod to send sniffer request to determine whether there is access to the specified resource. allow

  TRACE

  TRACEEcho request message requesting the server which receives the HTTP request method is mainly used for test or diagnosis.

  HTTP/1.1After increasing method

  In the HTTP/1.1following standards, and gradually expand a number of ways. Which is in use more  PATCHmethods?:

  PATCH

  PATCHThe method appears later, in 2010, it is RFC 5789 is defined standard. PATCHRequest and PUTthe request is similar to, for updating the same resource. Both the following differences:

  • But PATCHthe general part of the resources for the update, and PUToverall resources for the general update.
  • When the resource does not exist, PATCHit creates a new resource, and PUTwill only have to update the resource.

 

       Security and Idempotence 

  These HTTP requests on a method used with two basic characteristics, i.e., "Security" and "idempotent."

       For the above seven HTTP methods, GET, HEAD and OPTIONS methods are considered safe because they are designed to achieve access to the data, does not have the "border effect." As for the other four HTTP methods, since they cause a change of server resources, so the method is considered to be unsafe.

  Idempotent (the Idempotent) is a mathematical concept, where one indicates a boundary and transmitting multiple requests effect induced is the same. In the case where speed is not fast enough, the client sends a request can not be immediately respond, because if not determine whether the request was successfully submitted, it is possible to send the same request again another, determining the second idempotent a request is valid.

  Above three secure HTTP method (GET, HEAD, and OPTIONS) are idempotent method. Since PATCH DELETE request and a specific operation of existing resources, so they are idempotent method. For PUT request, only in the case of a server will add the corresponding resource does not exist, otherwise only for modification operations, so it is also idempotent methods. As for the last POST, because it always add operation, if the server receives the same twice POST operations, will result in two identical resource is created, so this is a non-idempotent methods.

  When we were designing the Web API should try to determine the logic processing of the request of the HTTP method of idempotent type. Because PUT is a power and other methods, so carry the same resource PUT request should not cause the change of state resources, if we attach a self-growth in the resource counter indicates the number is modified, it actually undermines the idempotent type.

        

       Statelessness

  RESTful state as long as the maintenance of resources, without the need to maintain client state. For it is, each request is new, as it requires a corresponding operation for this request, information need not be recorded down to this request for subsequent processing from the same client requests.

  For these two characteristics described above, we RESTful, and they asked us to meet all these features do something, but it is only the stateless asked us what not to do, because HTTP itself is stateless. For example, a web page by obtaining records match the query call Paging Web API. In general, the page navigation has recorded the previous page and the next page of the "previous" and "next" link for presenting the current page. So now there are two ways to achieve return records up and down the page.

  • Web API will not only define actions based on the specific data query definition of the relevant page, but also define a separate operation for such a request "Previous" and "Next." Its own will on the page every time the returned data is saved locally according to the client Session ID, in order to be able to know specifically what the previous and next page.
  • Web API will define actions based on the specific data query definition of the relevant page, the current page number to return data from the client to maintain.

  The first looks like a very "smart", is actually a superfluous practice, because it undermines the stateless nature of the Web API. Design stateless Web API Web API not only make themselves look simple and refined, but also because of the deduction for the client's "affinity (Affinty)" so that we can effectively implement load balancing, because the only way the cluster each server for each client is equivalent.

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11493431.html