How to get the origin URL from a “doPost” request

2019-05-04 09:05发布

问题:

I've been trying to identify the origin of a POST request made to a Google Apps Script doPost() content service;

function doPost(request) {
   // Something like this:
   var originURL = request.headers.URL; // http://myurl.com

}

Since I have published it ("Deploy as web app"), to 'Anyone, even anonymous', it has the following header:

access-control-allow-origin: *

So I want to control it's access in my code.

Is it possible?

回答1:

We can not use direct post method in other aplication but you can use URL parameters passing try following. Publishing script makes sure you have updated version and copy /exec link. you can pass URL parameters like https://script../../exec?=para1=1012D.

More details Click Here