google-apps-script - UrlFetchApp 和 doPost(e),相同的代码,不同的项目,不同的行为
问题描述
正如我在标题中所说,我在前端和后端测试项目(前端:UrlFetchApp
| 后端:)doPost(e)
和开发项目上得到了相同的代码。
由于我是 Google Apps 脚本编程的新手,我在一个 gmail 帐户中做了一个测试项目,以验证两个不同电子表格之间的 fetchUrlApp 和 doPost 通信等过程。开发项目在另一个帐户上用作预生产项目。
后端脚本在测试和开发项目中都部署为 Web 应用程序新版本发布方法是在测试项目上加载示例基本 JSON 我在后端获得我的 JSON,但在开发项目上没有。
这是代码和结果
后端doPost代码:
function doPost(e) {
Logger.log("I was called");
if (typeof e != 'undefined');
var data = JSON.parse(e.postData.contents);
var ss = SpreadsheetApp.openById("my-backend-id");
var sheet = ss.getSheetByName("Log");
sheet.getRange(1, 1).setValue(JSON.stringify(data))
//Logger.log(JSON.stringify(data));
return ContentService.createTextOutput(JSON.stringify(e));
};
前端提交帖子请求:
function test_rapide(){
var data = {"id":"xyz","name":"xy"};
var ret = makeRequest("https://my-web-app-URL/exec", data);
var content = ret.getContentText();
Logger.log(content);
};
测试项目成功的结果:
frontend log:
2020-07-03 14:31:33:364 +1100 003093 INFO {"contextPath":"","queryString":"","postData":{"contents":"{\"id\":\"xyz\",\"name\":\"xy\"}","length":24,"name":"postData","type":"application/json"},"parameters":{},"parameter":{},"contentLength":24}
backend log:
2020-07-03 14:31:32:148 +1100 000625 INFO I was called
2020-07-03 14:31:32:322 +1100 000799 INFO [object Object]
2020-07-03 14:31:32:901 +1100 001378 INFO {"id":"xyz","name":"xy"}
开发项目的结果失败:
frontend log:
"2020-07-03 15:05:13:886 +1100 000733 INFO Drive Sorry, unable to open the file at this time.Please check the address and try again.Get stuff done with Google Drive Apps in Google Drive make it easy to create, store and share online documents, spreadsheets, presentations and more. Learn more at drive.google.com/start/apps."
backend log:
nothing```
解决方案
推荐阅读
- javascript - 无法在没有得到语法或调用未定义函数错误的情况下将 JQuery 添加到 wordpress
- c - fscanf 在文件末尾返回 3 而不是 -1 (EOF)
- intellij-idea - 如何为 IntelliJ 中的所有 Rust/Cargo 测试设置 --nocapture 标志?
- jsf - Primefaces f:facet name="first" and "last" in h:head 不用于订单
- asp.net-mvc - InvalidOperationException:不正确的内容类型:Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
- angular - Bootstrap NgbDate 日期范围日历 - “TypeError:无法读取未定义的属性‘等于’”
- swift - 如何检查 Airpods 是否连接到 iPhone?
- forms - React Native - 如何验证文本输入的正确性?
- perl - 如何使用 Net::SMTP::TLS 发送电子邮件附件
- javascript - 在其他组件中使用 react this.state