是 HTTP“HEAD”吗?动词在网络开发中有用吗?
I've read the w3.org spec on the 'HEAD' verb, and I guess I'm missing something. I can't see how it would be useful.
Is the HTTP 'HEAD' verb useful in web development?
If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 RFC2616:
HEAD 优于 GET 的原因是由于响应中缺少消息正文,因此它适用于您想要确定内容是否已更改的场景 - 最后修改时间或内容长度的更改通常意味着这。
另外,HEAD 请求将提供一些有关服务器设置的信息(无论是 IIS/Apache 等),除非服务器被屏蔽;当然,这在所有响应中都可用,但 HEAD 是首选,尤其是当您不知道响应的大小时。 HEAD 也是确定站点是否正常运行的最简单方法;消息正文的无关性再次使 HEAD 成为理想的候选者。
我对此不确定,但 RSS/ATOM 提要阅读器会使用 HEAD 而不是 GET 来确定提要的内容是否已更改。
From RFC2616:
The reason why HEAD is preferred to GET is due to the absence of the message body in the response making it using in scenarios where you want to determine if the content has changed at all - a change in the last modified time or content length usually signifies this.
Also, a HEAD request will provide some information about the server setup (whether it is IIS/Apache etc.), unless the server was masked; of course, this is available in all responses, but HEAD is preferred especially when you don't know the size of the response. HEAD is also the easiest way to determine if a site is up or down; again the irrelevance of the message body makes HEAD the ideal candidate.
I'm not sure about this, but RSS/ATOM feed readers would use HEAD over GET to ascertain if the contents of the feed have changed.
HTTP HEAD 还可用于在对某些大数据进行 HTTP PUT/POST 之前对 Web 服务器进行预身份验证。如果没有第一个 HEAD 请求,您将两次向 Web 服务器发送大数据(因为第一个请求将返回带有 WWW-authenticate 标头的 401 未经授权的响应)。
The HTTP HEAD can also be used to pre-authenticate to web server, before you do HTTP PUT/POST of some large data. Without the first HEAD request, you would be sending the large data to web server twice (because the first request would return 401 unauthorized reponse with WWW-authenticate header).
它主要供浏览器和代理确定是否可以使用 Web 文档的缓存副本,而无需下载整个内容(这会违背缓存的目的)。
It's mainly for browsers and proxies to determine whether they can use a cached copy of the web document without having to download the whole thing (which would rather defeat the purpose of a cache).
是的,HTTP 'HEAD' 动词在 Web 开发中很有用。它允许客户端检索有关资源的元数据,而无需获取整个内容,这对于检查资源可用性、验证标头或执行轻量级检查等任务非常有用,而无需传输不必要的数据。
Yes, the HTTP 'HEAD' verb is useful in web development. It allows clients to retrieve metadata about a resource without fetching the entire content, which can be beneficial for tasks like checking resource availability, verifying headers, or performing lightweight checks without transferring unnecessary data.