Google App 脚本:带有标头的 URLFetchApp.fetch [英] Google App Script: URLFetchApp.fetch with header
本文介绍了Google App 脚本:带有标头的 URLFetchApp.fetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 Rainforestqa API 获取数据,但要获得访问权限,我需要将我的 api_key 作为标头发送.我已有的代码如下,
I'm trying to fetch data from the rainforestqa API but to gain access I need to send my api_key as a header. The code I already have is as follows,
var header = {
"access-control-allow-headers":"Content-Type",
"CLIENT_TOKEN" : "API-TOKEN"
};
var options = {
"method" : "post",
"header" : header
};
UrlFetchApp.fetch("https://app.rainforestqa.com:443/api/1/runs/TESTNUMBER/tests.json?result=failed", options);
但这会返回 405 错误.有没有人知道为什么这不起作用?
But this returns 405 error. Does anyone have any ideas why this isn't working?
谢谢
推荐答案
结果如下,我基本上是通过反复试验得到的.
It turns out the answer is as follows, I basically got to this via trial and error.
$var options = {
"async": true,
"crossDomain": true,
"method" : "GET",
"headers" : {
"CLIENT_TOKEN" : "my-api-key",
"cache-control": "no-cache"
}
};
var response = UrlFetchApp.fetch("https://app.rainforestqa.com:443/api/1/runs/test_id/tests.json?result=failed", options);
这篇关于Google App 脚本:带有标头的 URLFetchApp.fetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文