【发布时间】:2020-06-01 19:12:08
【问题描述】:
我正在开发一个小型 web 应用程序来自学一些 gcloud 和 js。目前正在尝试使用 axios 从谷歌云功能向 Web api 发送获取请求。任何指导将不胜感激。
web api在header中需要以下参数 接受:应用程序/json APIKey:APIKEY
我一直在尝试使用How to set header and options in axios? 中的代码 和 axios 信息,但我不断收到错误 (SyntaxError: Unexpected token)
Index.JS 目前看起来是这样的
const axios = require("axios");
exports.run = async(req, res) => {
axios.get('APIURL', {
headers: {
'Accept': 'application/json';
'APIKey': 'KEY'
}
}).then((response) => {
res.status(200).send(response.data);
console.log(response);
}, (error) => {
res.status(500).send(response.data);
console.log(error);
});
};
package.json
{
"name": "YOUR_NAME",
"version": "0.0.1",
"dependencies": {
"axios": "^0.19.2"
}
}
【问题讨论】:
-
请编辑问题以显示完整的错误消息,并指出它所指的代码行。
-
错字:你使用了
;,而你应该使用,
标签: javascript google-cloud-platform axios google-cloud-functions