问题模块 框架类型 问题类型 终端类型 AppID 基础库版本
云开发 微信小程序 Bug 工具 wx1ff8c5b9ba3bb104 2.3.0
const cloud = require('wx-server-sdk')
var superagent = require('superagent')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
superagent
.get('https://www.baidu.com/s?tn=80035161_2_dg&wd=superagent')
.end(function(req,res){
console.log('结果'+res)
})
console.log('3')
} 日志
START RequestId: a5f0f615-c6e2-11e8-9abf-52540064d067
Event RequestId: a5f0f615-c6e2-11e8-9abf-52540064d067 Event:{"userInfo":{"appId":"wx1ff8c5b9ba3bb104","openId":"oWOHt0MMxScoIvxqKe-GcabQ0R3s"}}
2018-10-03T08:02:18.423Z a5f0f615-c6e2-11e8-9abf-52540064d067 { userInfo:
{ appId: 'wx1ff8c5b9ba3bb104',
openId: 'oWOHt0MMxScoIvxqKe-GcabQ0R3s' } }
2018-10-03T08:02:18.424Z a5f0f615-c6e2-11e8-9abf-52540064d067 { callbackWaitsForEmptyEventLoop: [Getter/Setter],
done: [Function: done],
succeed: [Function: succeed],
fail: [Function: fail],
memory_limit_in_mb: 256,
time_limit_in_ms: 20000,
request_id: 'a5f0f615-c6e2-11e8-9abf-52540064d067',
environ: 'TENCENTCLOUD_SECRETID=AKIDh8bdibed7kOg2sXlMqSTzaeK6PN7VV2w;TENCENTCLOUD_SECRETKEY=2nHZ3U3JVCYQpp3tYxP3sYdUw33seMiZ;TENCENTCLOUD_SESSIONTOKEN=d7175f626718a6b48d4916c44ef1b1a69f32456d40001' }
2018-10-03T08:02:18.425Z a5f0f615-c6e2-11e8-9abf-52540064d067 3
END RequestId: a5f0f615-c6e2-11e8-9abf-52540064d067
Report RequestId: a5f0f615-c6e2-11e8-9abf-52540064d067 Duration:20.079ms Memory:256MB MaxMemoryUsed:0.871094MB
微信小程序开发问题解答
微信小程序开发者回答:const cloud = require('wx-server-sdk')var superagent = require('superagent')cloud.init()
// 云函数入口函数exports.main = async (event, context) => {
return new Promise(function(resolve, reject) {
try {
superagent.get('https://www.baidu.com/s?tn=80035161_2_dg&wd=superagent'').end(function(req, res) {
if (res.status == 200) {
return resolve(res);
} else {
return reject(req)
}
})
} catch (e) {
return reject(e)
}
});
}
微信小程序开发者回答:
请问 superagent 这个包需要自己手动npm安装吗?
微信小程序开发者回答:
对的 npm install superagent 就就可以了
微信小程序开发者回答:
const rp = require('request-promise');
// 云函数入口函数
exports.main = async(event, context) => {
var res = await rp(
{
method: 'get',
uri: 'https://xxxx.com',
qs: { },//参数
headers: {},//请求头
json: true //是否json数据
}
).then(( body) => {
return body
}).catch(err => {
return err;
})
return res;
}
// 用 request-promise更简单一点
微信小程序开发者回答:
//npm install request-promise
微信小程序开发者回答:
谢谢
本文网址:http://www.91bianli.com/kaifazhinan/76127.html