Google App脚本通过参数获取对另一个脚本的请求 [英] Google App Script make get request to another script with parameters
问题描述
我有两个Google脚本:
I have two google scripts:
1)带有URL的脚本A说sa/exec,它接受参数a,b,c
1) Script A with url say sa/exec which accepts parameters a,b,c
2)网址为sb/exec的脚本B
2) Script B with url say sb/exec
我必须从脚本B调用脚本A的doGet(e).我可以手动键入浏览器,例如sa/exec?a = vala& b = valb& c = valc.在Google脚本中,我可以这样:
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));
但这是一种非常容易出错的方式,因为我们必须手动转义特殊字符,并还要注意有效负载中的url编码.那么,是否有类似Url Builder的工具可以在这种情况下提供帮助并节省我的时间和精力?
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?
推荐答案
使用 encodeURI()或 encodeURIComponent().
这篇关于Google App脚本通过参数获取对另一个脚本的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!