各位大佬,用post访问nodejs云函数url,返回的event是event.body的内容,是怎么回事?详细如下
//云函数代码
exports.main = async (event, context) => {
console.log("event", event)
return event
};
//访问链接的代码
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);
});
然后访问链接接收到的内容和云函数打印中的内容不同。
//这是云函数打印的
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:*}}
//这是访问链接打印的
res { test: 'test123' }
很明显,返回的event不是event,而是event.body。不明白这里为什么不同,有大佬解答一下吗?
相似问题