在 JavaScript 中,有没有一种方法可以检索 URL 的内容类型而不检索整个文件?
我想确定给定的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以做一个http HEAD。 使用 JavaScript 访问网页的 HTTP 标头对此进行了介绍
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
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html