什么是HTTP方法的幂等性? [英] What is idempotency in HTTP methods?
问题描述
我已阅读HTTP文档,但我无法理解Idempotency是什么。请有人帮忙。
提前致谢。
I've read HTTP documentation, but I cant understand what is Idempotency. Can someone help, please. Thanks in advance.
推荐答案
Idempotency 是HTTP方法的一个属性。可以多次执行具有幂等HTTP方法的请求,并且将产生相同的结果。
Idempotency is a property of HTTP methods. A request with an idempotent HTTP method can be performed multiple times and the same result will be produced.
让我们来看看 RFC 7231 ,该文档定义了HTTP / 1.1协议的语义和内容。
Let's have a look at the RFC 7231, the document defines the semantics and the content of the HTTP/1.1 protocol.
HTTP方法可以安全:
如果请求方法的定义语义为
基本上是只读的,则视为安全强>;即,由于
对目标资源应用安全方法,客户端不会请求并且
不期望原始服务器上的任何状态更改。 [...]
Request methods are considered "safe" if their defined semantics are essentially read-only; i.e., the client does not request, and does not expect, any state change on the origin server as a result of applying a safe method to a target resource. [...]
在本规范定义的请求方法中, GET
, HEAD
,
OPTIONS
, TRACE
方法定义为安全。 [...]
Of the request methods defined by this specification, the GET
, HEAD
,
OPTIONS
, and TRACE
methods are defined to be safe. [...]
idempotent :
如果对
的预期影响是多个相同的服务器,则请求方法被视为幂等使用该方法的请求是
与单个此类请求的效果相同。在本规范定义的请求方法
中, PUT
, DELETE
,以及安全请求方法
是幂等的。 [...]
A request method is considered "idempotent" if the intended effect on
the server of multiple identical requests with that method is the
same as the effect for a single such request. Of the request methods
defined by this specification, PUT
, DELETE
, and safe request methods
are idempotent. [...]
总结一下,HTTP方法被归类为关注:
Summarizing, the HTTP methods are classified as following:
+---------+------+------------+
| Method | Safe | Idempotent |
+---------+------+------------+
| CONNECT | no | no |
| DELETE | no | yes |
| GET | yes | yes |
| HEAD | yes | yes |
| OPTIONS | yes | yes |
| POST | no | no |
| PUT | no | yes |
| TRACE | yes | yes |
+---------+------+------------+
这篇关于什么是HTTP方法的幂等性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!