首页 > 解决方案 > 使用 fetch API 忽略条件 GET

问题描述

我正在使用 Discord.js/Node.js获取和解析 RSS 提要 ( https://www.mangaupdates.com/rss.php )。我目前正在尝试添加条件If-Modified-Since标头以向 RSS 提要发出条件 GET 请求。这是我的代码:

fetch(mangaUpdatesRSS, {
  method: 'GET',
  headers: {'If-Modified-Since': new Date().toUTCString()}
})
.then(res => {
  console.log(res.status);

响应状态始终200是即使它应该仅在自fetch调用命令时被修改时才发出请求。

标签: javascriptnode.jshttpfetch-apiif-modified-since

解决方案


即使请求的资源是最新的,Fetch API 也会在内部替换304200你对此无能为力。

查看Service Worker / fetch() 中的识别 HTTP 304


推荐阅读