GET
and POST
是两种不同类型的 HTTP 请求。
根据维基百科 http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol:
GET请求指定资源的表示。请注意,GET 不应用于会产生副作用的操作,例如使用它在 Web 应用程序中执行操作。原因之一是 GET 可能被机器人或爬虫任意使用,它们不应该考虑请求应引起的副作用。
and
POST将要处理的数据(例如,来自 HTML 表单)提交到所识别的资源。数据包含在请求正文中。这可能会导致创建新资源或更新现有资源或两者兼而有之。
所以本质上GET
用于检索远程数据,并且POST
用于插入/更新远程数据。
HTTP/1.1 specification (RFC 2616) section 9
Method Definitions http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 contains more information on
GET
and
POST
as well as the other HTTP methods, if you are interested.
除了解释每种方法的预期用途之外,该规范还提供了至少一个实际原因GET
应该只用于检索数据:
使用 HTTP 协议的服务的作者不应该使用基于 GET 的表单来提交敏感数据,因为这会导致该数据被编码在 Request-URI 中。许多现有服务器、代理和用户代理会将请求 URI 记录在第三方可能可见的某个位置。服务器可以使用基于 POST 的表单提交来代替
Finally, an important consideration when using
GET
for AJAX requests is that some browsers - IE in particular - will cache the results of a
GET
request. So if you, for example, poll using the same
GET
request you will always get back the same results, even if the data you are querying is being updated server-side. One way to alleviate this problem is to make the URL unique for each request by appending a timestamp.