doPost(e)不返回参数,但doGet(e)做? [英] doPost(e) does not return parameters but doGet(e) does?

查看:166
本文介绍了doPost(e)不返回参数,但doGet(e)做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序包含以下 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:// *发布的网址* /用户说:
{
queryString:testparamA = abc& testparamB = bcd& testparamC = cde,
parameter:
{
testparamA:abc,
testparamB :bcd,
testparamC:cde
},
contextPath:,
参数:
{
testparamA:[abc],
testparamB:[bcd],
testparamC:[cde]
},
contentLength :-1
}

鉴于, POST POST http:// *发布的URL * / + params 返回:

<$ p $用户说:
{
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后的响应)




Nowhere on the internet is this specific problem or a fix for it mentioned, so here goes:

My app contains the following doGet() and doPost() functions:

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 returns:

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
}

Whereas, POST http://*published URL*/+params returns:

User says:
{
  "queryString":null,
  "parameter":{},
  "contextPath":"",
  "parameters":{},
  "contentLength":0
}

My goal is to access the POST parameters. But something seems to be blocking the script from fetching them when transmitted using the POST method. GET seems to work just fine.

What am I missing and what is the solution?

解决方案

POST and GET works perfectly fine for me using the exact same code you posted. My guess is that you are not testing the POST correctly.

Here is my published URL. The code behind is a copy/paste of your sample -

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

Test it from http://hurl.it (simple REST tester in a browser) and works without any problem.

Request (make sure to check follow redirects) -

Response (response after the redirect for one time ContentService URL for both GET and POST)

这篇关于doPost(e)不返回参数,但doGet(e)做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆