Can I use POST
method to get data from the server and GET
method to post data to the server?
问题:
回答1:
GET
and POST
methods exist for different purposes. Their semantic and use are described in the RFC 7231, one of the references for the HTTP/1.1 protocol.
See the quotes below:
4.3.1. GET
The
GET
method requests transfer of a current selected representation for the target resource.GET
is the primary mechanism of information retrieval and the focus of almost all performance optimizations. Hence, when people speak of retrieving some identifiable information via HTTP, they are generally referring to making aGET
request.[...]
A payload within a
GET
request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.The response to a
GET
request is cacheable; [...]
4.3.3. POST
The
POST
method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics. For example,POST
is used for the following functions (among others):
Providing a block of data, such as the fields entered into an HTML form, to a data-handling process;
Posting a message to a bulletin board, newsgroup, mailing list, blog, or similar group of articles;
Creating a new resource that has yet to be identified by the origin server; and
Appending data to a resource's existing representation(s).
[...]
Responses to
POST
requests are only cacheable when they include explicit freshness information. However,POST
caching is not widely implemented.