在 JavaScript 中,有没有一种方法可以检索 URL 的内容类型而不检索整个文件?

发布于 2024-10-05 10:05:32 字数 90 浏览 0 评论 0原文

我想确定给定的 URL 是否是图像而不依赖于文件的扩展名。在 JavaScript 中,有没有一种方法可以获取 URL 的 HTTP 响应标头而不检索文件的全部内容?

I would like to determine if a given URL is an image without relying on the file's extension. In JavaScript, is there a way to get a URL's HTTP response headers without retrieving the entire contents of the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

归途 2024-10-12 10:05:32

你可以做一个http HEAD。 使用 JavaScript 访问网页的 HTTP 标头对此进行了介绍

HEAD 方法与 GET 相同
除了服务器不得返回
响应中的消息正文。这
HTTP 中包含的元信息
响应 HEAD 请求的标头
应与信息相同
响应 GET 请求而发送。
该方法可用于获取
有关实体的元信息
请求暗示没有
转移实体本身。
该方法常用于测试
超文本链接的有效性,
可访问性和最近的
修改。

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9。 html

You can do an http HEAD. This is covered in Accessing the web page's HTTP Headers in JavaScript

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.

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

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