# RFC

## 1. Safe Method（安全的方法）

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered “safe”. This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

• GETHEAD方法不应该具有除了检索以外其他的意义，标准约定的是在去查看或者搜索服务器资源时候，使用这两个方法，这样来看，这两个方法应当是被认为安全的。
• 检索资源这种行为也可以发生在当用户使用POSTPUTDELETE这类方法的请求的时候，这个时候用户可能就请求了一个不安全的动作

## 2.Idempotent Method(幂等的方法)

Methods can also have the property of “idempotence” in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request.The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.

GETHEADPUTDELETEOPTIONTRACE都享有这个特性，而这里面不包含POST

# 呼之欲出的答案

GET的设计用于获取和检索资源，这种行为应该不产生副作用从而幂等。需要强调的是幂等不代表调取一次或者多次得到的结果不同，而是对资源的状态或者服务器是否产生不一样的影响。比如：GET http://www.baidu.com/article?id=1，不会改变id为1的资源状态，不论调用一次还是多次都没有副作用。

DELETE方法用于删除资源，有副作用，但满足幂等性。比如：DELETE http://www.baidu.com/article?id=2，调用了一次或者多次，都只代表删除id为2的文章，带来的对服务器的影响是相同的。

RFC上的说法本质也是这个意思：

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request – the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource.

• 全部
• 标签
• 友链