0

我是一个超级 n00b,试图使用 node.js 向 Google Cloud Function 中的 FreshSales 发出 HTTP 请求。
问题:
  • 节点不够熟练,无法进行适当的谷歌搜索
  • 没有足够的开发词汇来理解我在网上找到的内容

但是,这是我编写的代码(基于我在网上找到的 GCF 示例):


/**
 * HTTP Cloud Function that makes an HTTP request
 *
 * @param {Object} req Cloud Function request context.
 * @param {Object} res Cloud Function response context.
 */
exports.makeRequest = async (req, res) => {
    const url = 'https://mycompany.myfreshworks.com/crm/sales/api/contacts/123456'; // URL to send the request to
    const options = {
        method: "GET",
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Token token=BLABLABLA"
        }
    };
    console.log(options);
    const response = await fetch(url, options);

    console.log(response.body)
    console.log("Response Status : " + response.status)

    res.sendStatus(response.ok ? response.body : response.status);
}; 

我得到的答案是:函数执行耗时 1033 毫秒,完成状态为:“连接错误”,而我很想得到某种 JSON 响应。
我真的不明白我的错误在哪里,以及我是否在设置或 index.js 函数(上图)中出错了。
有人可以帮我吗?
即使是“观看视频”的建议也会有所帮助!谢谢

4

0 回答 0