uni-app真机调试报错request:fail abort解决方法

Android端真机调试访问本地接口数据时报错:request:fail abort

uni-app真机调试报错request:fail abort解决方法

报错代码

onLoad: function(e) {
uni.request({
url: 'http://localhost:8088/api/Gift',
method: 'GET',
data: {},
success: (res) => {
this.GiftInfo = res.data;
},
fail: (fa) => {
console.log(fa);
}
})
}

本地接口访问没有问题:

uni-app真机调试报错request:fail abort解决方法

DCloud社区相关问答:https://ask.dcloud.net.cn/question/80062

uni.request官方文档:https://uniapp.dcloud.io/api/request/request

解决方法:

  • 增加参数sslVerify,设置为false,不验证 ssl 证书
  • http换成https
  • 使用普遍受信的证书
  • localhost换成本地ip

修改后代码:

onLoad: function(e) {
uni.request({
url: 'https://ip:端口号/api/Gift',
method: 'GET',
data: {},
sslVerify: false,
success: (res) => {
this.GiftInfo = res.data;
},
fail: (fa) => {
console.log(fa);
}
})
}

上述代码访问本地接口数据成功!

End!

上一篇:ios dyld: Library not loaded: @rpath/xxx.framework/xxx 之根本原因


下一篇:dyld: Library not loaded: @rpath/XCTest.framework/XCTest Referenced from: /private/var/mobile/Conta