使用非常简单的缓存语义:如果参数相同(当然 URL 也相同),那么它就是成功的。那可能吗?推荐?
最佳答案
对应RFC 2616在第 9.5 节 (POST) 中,如果您使用适当的 header ,则允许缓存对 POST 消息的响应。
Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.
请注意,同一 RFC 在第 13 节(HTTP 中的缓存)中明确指出缓存必须在 POST 请求 之后使相应的实体无效。
Some HTTP methods MUST cause a cache to invalidate an entity. This is either the entity referred to by the Request-URI, or by the Location or Content-Location headers (if present). These methods are:
- PUT - DELETE - POST
我不清楚这些规范如何允许有意义的缓存。
这在RFC 7231中也得到反射(reflect)和进一步阐明。 (第 4.3.3 节),它废弃了 RFC 2616。
Responses to POST requests are only cacheable when they include
explicit freshness information (see Section 4.2.1 of [RFC7234]).
However, POST caching is not widely implemented. For cases where an origin server wishes the client to be able to cache the result of a POST in a way that can be reused by a later GET, the origin server MAY send a 200 (OK) response containing the result and a Content-Location header field that has the same value as the POST's effective request URI (Section 3.1.4.2).
据此,缓存的 POST 的结果(如果服务器指示了此能力)随后可以用作对同一 URI 的 GET 请求的结果。
关于http - 是否可以在 HTTP 中缓存 POST 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/626057/