api - HTTP HEAD 动词的状态码

标签 api http rest

根据 RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html :

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be used to update a previously cached entity from that resource. If the new field values indicate that the cached entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or Last-Modified), then the cache MUST treat the cache entry as stale.

根据这个定义,我们是否应该返回 200(例如相应的 GET 操作),或者我们是否应该返回 204 因为没有内容?

就我个人而言,我认为更好的解释是使用204 状态码。你的解释是什么?

最佳答案

参见 Section 10 ,它描述了状态代码。代码200的描述包括示例,它们包括HEAD。很明显,他们希望 HEAD 请求返回此代码。

204的描述解释了目的:

This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

关于api - HTTP HEAD 动词的状态码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19718927/

相关文章:

api - 授权 Azure AD 应用程序访问 RateCard API

java - 切换计算机时用 Java 发送电子邮件不起作用?

http - 允许仅从我的域提供某些文件(如字体)——特定的技术需求

ruby - 一种以宽容的方式在 Ruby 中标准化 URI/URL 的方法

java - 在 Linux 中使用 CURL 进行 HTTP POST

java - 使用 JUnit 测试自定义注释是否存在于方法级别

python - Autodesk Maya api - 导入几何体

api - 如何在静态网站中安全地存储 API key

java - 针对来自不同领域但具有共同关系的实体的 REST API 设计

rest - 如何在高级 REST API 客户端中使用来自 Chrome 的 cookie