互联网上没有提到这个特定问题或解决方案,所以这里是:
我的应用包含以下 doGet()
和 doPost()
函数:
function doGet (e){return ContentService.createTextOutput("User says: "+JSON.stringify(e))}
function doPost(e){return ContentService.createTextOutput("User says: "+JSON.stringify(e))}
GET http://*published URL*/+params
返回:
User says:
{
"queryString":"testparamA=abc&testparamB=bcd&testparamC=cde",
"parameter":
{
"testparamA":"abc",
"testparamB":"bcd",
"testparamC":"cde"
},
"contextPath":"",
"parameters":
{
"testparamA":["abc"],
"testparamB":["bcd"],
"testparamC":["cde"]
},
"contentLength":-1
}
而 POST http://*published URL*/+params
返回:
User says:
{
"queryString":null,
"parameter":{},
"contextPath":"",
"parameters":{},
"contentLength":0
}
我的目标是访问 POST
参数。但是在使用 POST
方法传输时,似乎有些东西阻止了脚本获取它们。 GET
似乎工作得很好。
我缺少什么以及解决方案是什么?
最佳答案
使用您发布的完全相同的代码,POST 和 GET 对我来说工作得非常好。我的猜测是您没有正确测试 POST。
这是我发布的网址。后面的代码是您的示例的复制/粘贴 -
https://script.google.com/macros/s/AKfycbzWZv9WUp7rUtOxZhhwuXPpuNXuvPGpiHyrcYrPeNLiusOWzazo/exec
从 http://hurl.it 测试它(浏览器中的简单 REST 测试器)并且可以正常工作。
请求(确保检查跟随重定向) -
响应(GET 和 POST 的一次 ContentService URL 重定向后响应)
关于parameters - doPost(e) 不返回参数,但 doGet(e) 呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13591488/