在云函数里通过request发起http请求(无论get或post),云函数运行貌似没出错,但是response处理没有被调用。而对方,压根就没有收到http请求。
尝试了其它域名,也是没有response。
const request = require(‘request’)
request.get(‘https://baidu.com’, function (error, response, body) {
console.log(‘error:’, error); // Print the error if one occurred
console.log(‘statusCode:’, response && response.statusCode); // Print the response status code if a response was received
console.log(‘body:’, body); // Print the HTML for the Google homepage.
});
wx2bf0ebe354aaac9c
2019-08-10 16:53:16
可复现,请盘查,谢谢。
const cloud = require( 'wx-server-sdk' ) //引入request-promise用于做网络请求 var rp = require( 'request-promise' ); cloud.init() // 云函数入口函数 exports.main = async (event, context) => { let url = 'https://www.baidu.com' ; return await rp(url) .then( function (res) { return res }) . catch ( function (err) { return '失败' }); } |
上面代码亲测可用,记得 npm install request-promise