根据 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/