提取但只能获得状态?

发布于 2025-01-30 05:39:18 字数 206 浏览 1 评论 0原文

附加新域时,我制作了逻辑,以检查该域是否正常通过获取工作。

fetch("https://" + domain).then((result)=>{
const isOk = result.status === 200
...
 })

但是,我认为通过获取以检查整个HTML文档以检查是否有效,这将是低效的。 如何仅获得状态价值?

When a new domain is attached, I made a logic to check whether the domain works normally through fetch.

fetch("https://" + domain).then((result)=>{
const isOk = result.status === 200
...
 })

However, I thought it would be inefficient to fetch the entire HTML doc through fetch just to check if it works.
How can I get only the status value?

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

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

发布评论

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

评论(1

双手揣兜 2025-02-06 05:39:18

您只能使用 <代码>头部 方法。服务器应与使用GET方法返回相同的标头,但没有正体。您可以使用 方法)选项

fetch(url, { method: 'HEAD' })

You can request only the headers, as opposed to the whole page, using the HEAD method. The server should return the same headers as it would if the GET method was used, but no body. You can request this behaviour using the method option:

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