所以我正在嘗試從 Github API 檢索 React 應用程序的回購數據。由于 API 的速率限制,我正在嘗試使用條件請求來檢查自上次請求以來數據是否已被修改,使用If-Modified-Since標頭。到目前為止,這是我的測試代碼:const date = new Date().toUTCString();fetch('https://api.github.com/users/joshlucpoll/repos', { headers: {'If-Modified-Since': date} }) .then((res) => { let headers = res.headers; console.log(headers) if (headers.get('status') === "304 Not Modified") { console.log("Not modified") } else { console.log("modified") } });每次運行此代碼時,我都會得到一個200 OK狀態,而不是304 Not Modified預期的狀態。資源在運行代碼時無法更新,但是,它始終輸出“未修改”...我不明白為什么這不起作用,我們將不勝感激!
來自 Github API 的奇怪響應(條件請求)
慕容森
2023-01-06 09:46:26