首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用post链接访问nodejs云函数,返回的event和打印的不一样,什么原因?

用post链接访问nodejs云函数,返回的event和打印的不一样,什么原因?

提问于 2021-12-19 22:07:37
回答 1关注 0查看 219

各位大佬,用post访问nodejs云函数url,返回的event是event.body的内容,是怎么回事?详细如下

代码语言:js
复制
//云函数代码
exports.main = async (event, context) => {
    console.log("event", event)
    return event
};
代码语言:js
复制
//访问链接的代码
axios({
    url: "https://*-test-2f2*-*.ap-shanghai.app.tcloudbase.com/test",
    method: "post",
    data: { test: "test123" }
}).then(res => {
    console.log("res", res.data);
}).catch(err => {
    console.log("err", err);
});

然后访问链接接收到的内容和云函数打印中的内容不同。

代码语言:js
复制
//这是云函数打印的
event{body:test223,headers:{accept:application/json, text/plain, */*,connection:keep-alive,content-length:7,content-type:application/x-www-form-urlencoded,host:*,user-agent:axios/0.24.0,x-client-proto:https,x-client-proto-ver:HTTP/1.1,x-daa-tunnel:hop_count=1,x-forwarded-for:*,x-forwarded-proto:https,x-nws-log-uuid:*,x-real-ip:*,x-stgw-time:1639922367.051,x-tencent-ua:Qcloud},httpMethod:POST,isBase64Encoded:false,multiValueHeaders:{accept:[application/json, text/plain, */*],connection:[keep-alive],content-length:[7],content-type:[application/x-www-form-urlencoded],host:[*],user-agent:[axios/0.24.0],x-client-proto:[https],x-client-proto-ver:[HTTP/1.1],x-daa-tunnel:[hop_count=1],x-forwarded-for:[*],x-forwarded-proto:[https],x-nws-log-uuid:[*],x-real-ip:[14.215.166.141],x-stgw-time:[1639922367.051],x-tencent-ua:[Qcloud]},path:/,queryStringParameters:{},requestContext:{appId:*,envId:*,requestId:*,uin:*}}
代码语言:js
复制
//这是访问链接打印的
res { test: 'test123' }

很明显,返回的event不是event,而是event.body。不明白这里为什么不同,有大佬解答一下吗?

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档