http fetch 提供与网络不同的状态?
http fetch gives different status than network?
我一定是做错了什么,但我正在尝试对服务执行 ping 操作,直到收到 200 响应。当我在浏览器 (chrome) 中查看网络选项卡时,我得到一个 304:
然而,当我打印出以下代码时:
const s1 = await fetch(`./${cluster}/api`)
const s2 = await fetch(`./${cluster}/dashboard`)
console.log(s1.status, s2.status)
我得到:
不好意思,上面写着 200 200。
为什么我在查看状态时得到 200,而在网络选项卡中得到 304?
正如您从 here 中看到的(向下滚动到“重定向”):
Normally, fetch transparently follows HTTP-redirects, like 301, 302 etc.
fetch
跟随 HTTP 重定向,所以你得到一个 304,然后 fetch 将从缓存中加载页面,因为 304 Not Modified
意味着缓存的页面仍然有效。
还工作阅读https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections#special_redirections
我一定是做错了什么,但我正在尝试对服务执行 ping 操作,直到收到 200 响应。当我在浏览器 (chrome) 中查看网络选项卡时,我得到一个 304:
然而,当我打印出以下代码时:
const s1 = await fetch(`./${cluster}/api`)
const s2 = await fetch(`./${cluster}/dashboard`)
console.log(s1.status, s2.status)
我得到:
不好意思,上面写着 200 200。
为什么我在查看状态时得到 200,而在网络选项卡中得到 304?
正如您从 here 中看到的(向下滚动到“重定向”):
Normally, fetch transparently follows HTTP-redirects, like 301, 302 etc.
fetch
跟随 HTTP 重定向,所以你得到一个 304,然后 fetch 将从缓存中加载页面,因为 304 Not Modified
意味着缓存的页面仍然有效。
还工作阅读https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections#special_redirections