Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

http - Why does the return response of google app script dopost() gets redirected?

I have a google app script deployed as a web app with doPost() handler . The handler function exposes a sort of remote procedure call functionality , and allows my embedded iot devices to POST parameters as a client , and receives status values , both in JSON format . I use bare metal C resources to do so , i.e. I implement basic HTTP POST request protocol on top of the TCP socket.

The POST request is straight forward , the doPost() handler is called , and it updates my Google Sheet with the send JSON parameters. The status of the app function ("OK" / "FAILED") is then returned to the client . Here is where things went south for me. The client , instead of receiving the POST response , receives a HTTP 302 redirect URL https://script.googleusercontent.com/xxxx with URL parameters . I now need to start an HTTP GET session with the new url, and then I receive the desired original POST response.

So it actaully works , and quite reliably so . But , what is the reason for that complicated redirection with a subsequent GET request ? Is it normal behavior , or am I overcooking / undercooking something , I am an embedded engineer , and therefore knowledge of HTTP is limited. Have I left a POST Header out in the original POST request .? I only support Content-Type and Content-Length in terms of the POST method.

Thanking you in advance.

question from:https://stackoverflow.com/questions/65873559/why-does-the-return-response-of-google-app-script-dopost-gets-redirected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have found an answer after struggling in the Google documentation:

Redirects:

For security reasons, content returned by the Content service isn't served from script.google.com, but instead redirected to a one-time URL at script.googleusercontent.com. This means that if you use the Content service to return data to another application, you must ensure that the HTTP client is configured to follow redirects. For example, in the cURL command line utility, add the flag -L. Check the documentation for your HTTP client for more information on how to enable this behavior.

Reference:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...