的doPost(五)不返回参数,但的doGet(E)呢?(doPost(e) does not re

2019-07-04 04:26发布

无处在互联网上为这一特定问题或它提到一个解决方法,所以这里有云:

我的应用程序包含以下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似乎工作就好了。

我在想什么,什么是解决方案?

Answer 1:

POST和使用您发布的完全相同的代码GET作品对我来说完全没有问题。 我的猜测是,你是不是正确测试POST。

这是我发布的URL。 后面的代码是你的样品的复制/粘贴 -

https://script.google.com/macros/s/AKfycbzWZv9WUp7rUtOxZhhwuXPpuNXuvPGpiHyrcYrPeNLiusOWzazo/exec

从测试http://hurl.it (在浏览器中简单的REST测试仪),并没有任何问题的作品。

请求(请务必检查进行重定向) -

响应(重定向一次性URL contentService的两个GET和POST之后响应)



Answer 2:

我觉得这是有点期待。 当一个人的HTTP GET的参数传递的URL。 当它是一个POST他们的有效载荷,而不是URL去。

尝试调用后这样的软件(Apps Script代码):

UrlFetchApp.fetch(scriptUrl, {method:'post', payload:'param1=value1&param2=value2'});


Answer 3:

但是我有同样的问题。 doGet(e)返回一个参数集合,但doPost(e)没有。 综观值e的脚本日志:

的doGet记录如下:

{queryString=param1=value1&param2=value2&param3=value3, 
parameter={param1=value1, param2=value2, param3=value3}, 
contextPath=, 
parameters={param1=[value1], param2=[value2], param3=[value3]},contentLength=-1}

doPost方法记录如下:

{queryString=lib=Ma1kfpb2uwfs976NQh3S0GV_Vnss8VuKo&appId=u33198874110&formId=xxxxxxxxxxxx&token=AJuLMu2XVXMgpvS-7l6mWLVDmxjYMA6ZEQ:1393694820550&gm1xs=&service=AKfycbzfP8gYQknL9dNG6SVf0LmPYy3xiEAtyFQ8AvJDwfs, 
parameter={gm1xs=, lib=Ma1kfpb2uwfs976NQh3S0GV_Vnss8VuKo, appId=u33198874110, param1=value1, formId=u33198874111, token=AJuLMu2XVXMgpvS-7l6mWLVDmxjYMA6ZEQ:1393694820550, param2=value2, param3=value3, service=AKfycbzfP8gYQknL9dNG6SVf0LmPYy3xiEAtyFQ8AvJDwfs},
contextPath=, contentLength=341}

所以在doGet是微不足道的通过循环e.parameters ,但在doPost必须遍历e.parameter代替,并妥善处理,你不在乎形式等参数。



文章来源: doPost(e) does not return parameters but doGet(e) does?