是 HTTP“HEAD”吗?动词在网络开发中有用吗?

发布于 2024-08-05 16:28:07 字数 211 浏览 6 评论 0原文

我已阅读 w3.org 关于“HEAD”动词的规范 ,我想我错过了一些东西。我看不出它有什么用处。

HTTP“HEAD”动词在 Web 开发中有用吗?

如果有用,怎么用?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

虚拟世界 2024-08-12 16:28:07

来自 RFC2616

该方法(HEAD)可用于获取
有关实体的元信息
请求暗示没有
转移实体本身。
该方法常用于测试
超文本链接的有效性,
可访问性和最近的
修改。

HEAD 优于 GET 的原因是由于响应中缺少消息正文,因此它适用于您想要确定内容是否已更改的场景 - 最后修改时间或内容长度的更改通常意味着这。

另外,HEAD 请求将提供一些有关服务器设置的信息(无论是 IIS/Apache 等),除非服务器被屏蔽;当然,这在所有响应中都可用,但 HEAD 是首选,尤其是当您不知道响应的大小时。 HEAD 也是确定站点是否正常运行的最简单方法;消息正文的无关性再次使 HEAD 成为理想的候选者。

我对此不确定,但 RSS/ATOM 提要阅读器会使用 HEAD 而不是 GET 来确定提要的内容是否已更改。

From RFC2616:

This method (HEAD) 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 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.

平安喜乐 2024-08-12 16:28:07

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).

情绪少女 2024-08-12 16:28:07

它主要供浏览器和代理确定是否可以使用 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).

梦忆晨望 2024-08-12 16:28:07

是的,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文