2***@qq.com
2***@qq.com
  • 发布:2022-03-14 10:23
  • 更新:2022-04-18 16:42
  • 阅读:652

云函数URL化后,访问失败

分类:uniCloud

云函数进行url化后,访问访问报错。
云函数片段:

测试情况如下:
使用uniCloud.callFunction 没有问题
console.log(event) 输出内容

{
"action": "functions.invokeFunction",
"env": "tcb-**-**",
"dataVersion": "2019-08-16",
"function_name": "mix-admin",
"request_data": "{\"module\":\"admin\",\"operation\":\"login\",\"token\":\"\",\"data\":{\"username\":\"\",\"password\":\"\"},\"clientInfo\":{\"PLATFORM\":\"h5\",\"OS\":\"windows\",\"APPID\":\"UNI6051151\",\"LOCALE\":\"zh-Hans\",\"DEVICEID\":\"16469622294892780966\",\"CLIENT_SDK_VERSION\":\"1.0.6\"},\"uniCloudClientInfo\":\"**"}",
"access_token": "eyJhbGciOiJIUzI1***6",
"seqId": "efbdf4334dc8f"
}

url化后,调用接口,返回获取不到参数
console.log(event) 输出 内容为:
{
"body": "{\"data\":{\"password\":\"\",\"username\":\"\"},\"module\":\"admin\",\"operation\":\"login\",\"token\":\"\"}",
"headers": {
"accept": "text/html,application/json,application/xhtml+xml,application/xml;q=0.9,/;q=0.8",
"accept-encoding": "gzip, deflate",
"accept-language": "zh-CN,zh;q=0.8",
"cache-control": "no-cache",
"connection": "keep-alive",
"content-length": "99",
"content-type": "application/json;charset=UTF-8",
"host": "**503d0ec.service.tcloudbase.com",
"pragma": "no-cache",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 Hutool",
"x-client-proto": "https",
"x-client-proto-ver": "HTTP/1.1",
"x-forwarded-for": "112.46.66.26",
"x-forwarded-proto": "https",
"x-real-ip": "112.46.66.26",
"x-stgw-time": "1647222906.700"
},
"httpMethod": "POST",
"isBase64Encoded": false,
"multiValueHeaders": {
"accept": ["text/html,application/json,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"],
"accept-encoding": ["gzip, deflate"],
"accept-language": ["zh-CN,zh;q=0.8"],
"cache-control": ["no-cache"],
"connection": ["keep-alive"],
"content-length": ["99"],
"content-type": ["application/json;charset=UTF-8"],
"host": ["**3d0ec.service.tcloudbase.com"],
"pragma": ["no-cache"],
"user-agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 Hutool"],
"x-client-proto": ["https"],
"x-client-proto-ver": ["HTTP/1.1"],
"x-forwarded-for": ["112.46.66.26"],
"x-forwarded-proto": ["https"],
"x-real-ip": ["112.46.66.26"],
"x-stgw-time": ["1647222906.700"]
},
"path": "/",
"queryStringParameters": {},
"requestContext": {
"appId": "1**495",
"envId": "t**-2dag36503d0ec",
"requestId": "2**05abd4abe8ded7c96",
"uin": "100022230573"
}
}

请问如何设置或者配置,才能使url化后云函数直接获取到body中的内容。

2022-03-14 10:23 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

JSON.parse(event.body), 注意错误处理

该问题目前已经被锁定, 无法添加新回复