vickyyiyi
vickyyiyi
  • 发布:2020-08-07 11:28
  • 更新:2023-04-01 22:13
  • 阅读:5760

【报Bug】在uniapp中访问uniCoud函数没有问题,在非uniapp下(VueCli)调用uniCloud云函数(URL化),接收不到参数返回错误

分类:uniCloud

产品分类: uniCloud/App

操作步骤:

直接在uniCloud云函数管理中点击“打开路径“”使用浏览器发送http get请求直接会返回一份.json文件下载,json的内容也是{"success":false,"error":{"code":"FunctionBizError","message":":查询参数对象值不能均为undefined"}}

预期结果:

预期返回success:true

实际结果:

{"success":false,"error":{"code":"FunctionBizError","message":":查询参数对象值不能均为undefined"}}

bug描述:

在非uniapp下调用uniCloud云函数(URL化),云函数接口接收不到参数返回
{"success":false,"error":{"code":"FunctionBizError","message":":查询参数对象值不能均为undefined"}}
我在VueCli中的调用(已配置跨域)
this.$axios.request({
url: "/http/getOrderList",
method: "POST",
params: {
"clientid": "test"
},
data: {
"clientid": "test"
}
}).then(function (response) {
if (response.status == 200) {
let res = response.data;
console.log(res);
}
});

这是unicloud的云端函数日志
请求入参: {
"args": {
"path": "/",
"httpMethod": "POST",
"headers": {
"content-length": "19",
"referer": "http://10.168.1.232:8081/",
"accept-language": "zh-CN,zh;q=0.9",
"cookie": "device_view=mobile; acw_tc=2760825415967703855132906e83cfe314eabf8ceb51db86535fea9471d97a",
"origin": "http://10.168.1.232:8081",
"x-forwarded-port": "8081",
"x-forwarded-for": "10.168.1.232, 113.240.217.101, 39.96.130.77",
"accept": "application/json, text/plain, /",
"x-real-ip": "113.240.217.101",
"host": "00740d08-edac-45b5-b502-9464f72ebf64.bspapp.com",
"content-type": "application/json;charset=UTF-8",
"x-forwarded-by": "172.20.8.35:80",
"accept-encoding": "gzip, deflate",
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
},
"queryStringParameters": {
"clientid": "test"
},
"isBase64Encoded": false,
"body": "{"clientid":"test"}"
},
"requestId": "ac1408231596770387253505674"
}
[getOrderList/ac1408231596770387253505674/1ms/ERROR] 查询参数对象值不能均为undefined
Error: 查询参数对象值不能均为undefined
at where (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:29919)
at exports.main (/tmp/function/__index.js:5:31)
at module.exports (/tmp/function/index.js:98:26)
at runUserFunction (/code/index.js:116:181859)
at (<anonymous>)
at _tickCallback (internal/process/next_tick.js:188:7)
请求响应状态: fail

在uniapp中访问没有问题可以,这是在hbuilder中uniapp访问成功的unicloud云端函数日志
请求入参: {
"args": {
"clientid": "460015167404213",
"clientInfo": {
"PLATFORM": "app-plus",
"APPID": "__UNI__56A1F08",
"CLIENT_SDK_VERSION": "1.0.0"
},
"uniIdToken": ""
},
"requestId": "ac1408241596769307977626975"
}
请求响应状态: success

2020-08-07 11:28 负责人:无 分享
已邀请:
a***@hotmail.com

a***@hotmail.com

url化调用等参数(args)是在网关帮你封装过的,其中的queryStringParameters和body中的就是参数
而使用uniCloud.callFunction调用的参数(args)是直接你自己组装的。
如果需要两者兼容,可以按照官方的封装来修改callFunction的data参数,云函数统一解析就行了

1***@qq.com

1***@qq.com

解决了吗

赫乌氨簧_黄

赫乌氨簧_黄

你好,请问你的解决了吗

j***@163.com

j***@163.com

https://uniapp.dcloud.net.cn/uniCloud/http.html#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4

y***@foxmail.com

y***@foxmail.com

我出现这个问题是因为在云函数中忘记接收到的event是一个集成请求,而不再仅仅是我传入的data。
使用get方法时,要在云函数中获取传入的data,需要写event.queryStringParameters。
文档中有提到相关的,具体部分在 普通云函数->云函数的入参,链接放下面了:
https://uniapp.dcloud.net.cn/uniCloud/http.html#input

要回复问题请先登录注册