You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Apps Script获取RSS Feed返回406错误

Google Apps Script请求RSS Feed返回406错误的排查

我编写了一个简单的Google Apps Script用于批量获取多个RSS Feed,代码如下:

for (let i = 0; i < rssUrls.length; i++) {
   const rssUrl = rssUrls[i];

   const response = UrlFetchApp.fetch(rssUrl);

   console.log(response.getContentText());
}

其中针对URL http://tenfootpole.org/ironspike/?feed=rss2 的请求始终失败,返回406 - Not Acceptable错误,响应内容如下:

<html><head><title>Error 406 - Not Acceptable</title><head><body><h1>Error 406 - Not Acceptable</h1><p>Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.</p></body></html>

该URL在浏览器、Postman甚至Google Sheets的=IMPORTFEED()函数中均可正常访问,我不清楚Google Apps Script(GAS)的请求有什么特殊性导致这个问题。

参考相关问题后,我尝试添加请求头并启用异常静默,修复代码如下:

const options = {
  headers: {
    Accept: '*/*'
  },
  'muteHttpExceptions': true
};

const response = UrlFetchApp.fetch(rssUrl, options);

console.log(response.getContentText());

但问题依旧存在,我尝试过多种内容类型、编码类型和语言的请求头组合,始终得到相同的406错误。我怀疑这个406错误其实是服务器对其他问题的默认响应,请问可能是什么原因?

内容的提问来源于stack exchange,提问作者Olobosk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 10:20:06