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

调用Google Apps Script POST请求报错:CORS及doGet未找到问题排查

Google Apps Script POST请求相关问题

报错情况

  1. Expo Web应用控制台报错:

Access to fetch at 'https://script.google.com/macros/s/MyScriptID/exec' from origin 'http://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

  1. 直接访问该Google Apps Script链接时,页面提示:
Script function not found: doGet

个人判断

我认为CORS策略并非问题根源,因为之前使用Google Apps Script Web应用时,只要脚本出错就会出现相同的CORS拦截报错。

相关代码

Expo Web的POST请求代码

const res = await fetch(process.env.EXPO_PUBLIC_SHEETSURL, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    
    body: JSON.stringify({
      'firstname': firstname,
      'lastname': lastname,
    })
    
  })
  
  const output = await res.text()
  console.log(output)

Google Apps Script代码

function doPost(e) {
  return ContentService.createTextOutput("Hello World!")
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 18:18:16