parameters - doPost(e) 不返回参数,但 doGet(e) 呢?

标签 parameters google-apps-script

互联网上没有提到这个特定问题或解决方案,所以这里是:

我的应用包含以下 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 测试器)并且可以正常工作。

请求(确保检查跟随重定向) -

request screenshot

响应(GET 和 POST 的一次 ContentService URL 重定向后响应)

response screenshot

关于parameters - doPost(e) 不返回参数,但 doGet(e) 呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13591488/

相关文章:

parameters - 如何在asp .net 4.5中将参数传递给gridView的SelectMethod

c# - Action 过滤器 Action 参数

sql - 如何在 Hibernate 日志中显示 SQL 参数?

javascript - 根据表单中提供的答案,将 lastRow 复制到基于不同工作表提交的表单上

google-apps-script - 如何解释Google服务的配额

javascript - 获取电子表格行的匹配值

android - 使用 savedInstanceState 和 onSaveInstanceState 重要吗?

java - 将当前执行函数的参数动态传递给其他函数

google-apps-script - 弹出授权码 DocumentApp - Google Apps 脚本

google-apps-script - google.script.run 的服务器响应处理程序