Google云端函数 – Nodejs错误,永远加载

const request = require('request'); exports.helloWorld = function helloWorld(req, res) { var headers = { 'scheme': 'https', 'authorization': 'Token 123', 'user-agent': 'mobile' }; var options = { url: 'https://url', headers: headers }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); res.status(200).send(response.body); } } request(options, callback); }; 

我可以提交一个没有问题的请求,但一旦我开始做一个请求头和选项,我不能让它在Google云端函数上正常工作。

请教我的错误

触发器types:HTTP触发器

这很可能是因为您使用request进行的调用返回错误,并且由于在错误情况下您不会使用res.end()或res.status(500).end()结束函数,Cloud函数不知道你的函数是否完成,所以只要运行它,直到超时被击中。

尝试:

 if (!error && response.statusCode == 200) { console.log(body); res.status(200).send(response.body); } else { console.log(error); res.status(500).send(error); } 

你应该得到一个回应没有挂起云function。