需要将此curl转换为谷歌应用程序脚本Urlfetch



我正试图将这个curl转换为谷歌应用程序脚本,但我收到了400个错误的请求

这是卷曲命令

curl --include 
--header "Authorization: Basic YXBpLXVzZXJuYW1lOmFwaS1wYXNzd29yZA=="  
--request POST 
--header "Content-Type: application/json" 
--data-binary "    {
"messages":[
{
"source":"php",
"body":"Jelly liquorice marshmallow candy carrot cake 4Eyffjs1vL.",
"to":"+61411111111"
},
{
"source":"php",
"body":"Chocolate bar icing icing oat cake carrot cake jelly cotton MWEvciEPIr.",
"to":"+61422222222"
}
]
}" 
'https://rest.clicksend.com/v3/sms/send'

我相信你的目标如下。

  • 您想将问题中的curl命令转换为Google Apps脚本

示例脚本:

function myFunction() {
const url = "https://rest.clicksend.com/v3/sms/send";
const params = {
method: "post",
headers: { Authorization: "Basic YXBpLXVzZXJuYW1lOmFwaS1wYXNzd29yZA==" },
contentType: "application/json",
payload: JSON.stringify({
"messages": [
{
"body": "Jelly liquorice marshmallow candy carrot cake 4Eyffjs1vL.",
"source": "php",
"to": "+61411111111"
},
{
"body": "Chocolate bar icing icing oat cake carrot cake jelly cotton MWEvciEPIr.",
"source": "php",
"to": "+61422222222"
}
]
})
};
const res = UrlFetchApp.fetch(url, params);
console.log(res.getContentText());
}

注:

  • 在这个示例脚本中,它假设curl命令运行良好。请小心
  • 如果您想查看响应标头,也可以使用getAllHeaders()。参考

参考:

  • UrlFetchApp.fetch(url,params(

相关内容

最新更新