问题
I have two google scripts:
1) Script A with url say sa/exec which accepts parameters a,b,c
2) Script B with url say sb/exec
I have to call doGet(e) of script A from script B. Manually I can do it by typing in browser like sa/exec?a=vala&b=valb&c=valc. And in google script, I can do it like this:
var params={
'method':'get',
'payload':'a=vala&b=valb&c=valc'
};
JSON.stringify(UrlFetchApp.fetch(url, params));
But its a very error prone way as we have to escape the special characters manually and also take care of url encoding in the payload. So is there something like Url builder which can come to aid in this situation and save my time and effort?
回答1:
Use encodeURI() or encodeURIComponent().
来源:https://stackoverflow.com/questions/25228684/google-app-script-make-get-request-to-another-script-with-parameters