doPost(e) does not return parameters but doGet(e) does?

后端 未结 3 1006
难免孤独
难免孤独 2021-01-06 23:59

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()

相关标签:
3条回答
  • 2021-01-07 00:24

    I think this is somewhat expected. When one does an HTTP GET the parameters are passed on the url. When it's a POST they go on the payload, not the url.

    Try calling post like this (Apps Script code):

    UrlFetchApp.fetch(scriptUrl, {method:'post', payload:'param1=value1&param2=value2'});
    
    0 讨论(0)
  • 2021-01-07 00:26

    I am having the same issue however. doGet(e) returns a parameters collection, but doPost(e) does not. Looking at the value e in the script log:

    DoGet logs this:

    {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 logs this:

    {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}
    

    So in the doGet it is trivial to loop through e.parameters, but in doPost you must loop through e.parameter instead, and deal with the other parameters from the form that you don't care about.

    0 讨论(0)
  • 2021-01-07 00:46

    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) -

    request screenshot

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

    response screenshot

    0 讨论(0)
提交回复
热议问题