我创建了一个非常基本的 Google Apps 脚本。这是我的doPost()和doGet():
function doPost(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function doGet(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function respond(response) {
return ContentService
.createTextOutput(response)
.setMimeType(ContentService.MimeType.JSON)
}
Run Code Online (Sandbox Code Playgroud)
我已经使用新版本部署了该应用程序。它设置为以我的身份运行,但每个人都可以运行它,包括匿名。
我正在通过从命令行运行 cURL 来测试端点,对于 GET,它按预期工作:
要求 -
curl -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Run Code Online (Sandbox Code Playgroud)
回复 -
{"result":"Hello world!"}
Run Code Online (Sandbox Code Playgroud)
但对于邮政:
要求 -
curl -H "Content-Length: 0" -D "p=p" -X POST -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Run Code Online (Sandbox Code Playgroud)
回复 -
Sorry, unable to open the file at this time.
Please check the address and try again.
Run Code Online (Sandbox Code Playgroud)
正如您从命令中看到的,我必须进行一些操作才能达到此目的:包括虚拟数据、添加内容长度标头以及添加 -L 标志以使用重定向。 …