You need to enable JavaScript to run this app. Google Apps Script中UrlFetchApp请求返回302状态码问题求助
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script中UrlFetchApp请求返回302状态码问题求助

问题根因

你遇到的302不自动跳转问题有两个核心原因:

  • UrlFetchApp 配置参数名错误:你使用的AllowAutoRedirect不是Google Apps Script UrlFetchApp支持的合法参数,正确的自动跟随重定向参数是followRedirects
  • 目标站点是ASP.NET构建,默认开启了Cookie支持自动检测逻辑,首次无Cookie请求会强制302跳转到带AspxAutoDetectCookieSupport=1的地址

修复方案

方案1:修正参数直接使用(最简便)

直接修正重定向参数名即可,UrlFetchApp会自动处理跳转和Cookie传递:

var options = {'muteHttpExceptions': true, 'followRedirects': true};
// 修正原URL多余的斜杠
var url = "https://www.auftrag.at/tenders.aspx"
var firstResponse = UrlFetchApp.fetch(url, options);
Logger.log(firstResponse.getContentText());
if(firstResponse.getResponseCode() == 200){
  // 原有逻辑
}

方案2:兼容特殊场景

如果修正参数后还是有跳转问题,可以直接请求带检测参数的地址,主动跳过ASP.NET的Cookie检测步骤:

var options = {'muteHttpExceptions': true, 'followRedirects': true};
// 直接使用带检测参数的目标地址
var url = "https://www.auftrag.at/tenders.aspx?AspxAutoDetectCookieSupport=1"
var firstResponse = UrlFetchApp.fetch(url, options);
// 后续逻辑不变

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 22:48:02