http - 是否可以在 HTTP 中缓存 POST 方法?

标签 http post http-caching

使用非常简单的缓存语义:如果参数相同(当然 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/

相关文章:

http - HTTP header Vary :*是什么意思

html - 动态内容的 css 文件中的数据 URI

c# - 如何阻止 HTTP 转义引号?

c# - 如何通过我的 Visual Studio 访问 Google 项目 [.Net]?

angularjs - Angular $http 回调不适用于 Chrome 中的 HTTP 304

PHP 重定向代码 307 将方法从 POST 更改为 GET

c# - 使用 WebClient 将数组作为消息正文的一部分传递以进行发布操作

java - 解析帖子响应的主体,Java

asp.net-mvc-3 - ASP.NET MVC3 获取 View 任何部分的最后修改时间?

c# - 如何禁用所有 WebApi 响应的缓存以避免 IE 使用(来自缓存)响应