uni-app-device debugging error request: fail abort Solution

End Android device debugging error when accessing local data interfaces: request: fail abort

Error codes

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);
		}
	})
}

Local interface to access is no problem:

DCloud community related Q: https://ask.dcloud.net.cn/question/80062

uni.request official document: https://uniapp.dcloud.io/api/request/request

Solution:

  • Increase parameter sslVerify, set to false, no validation ssl certificates
  • http to https
  • Widespread use of trusted certificate
  • localhost into local ip

After modifying the code:

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);
		}
	})
}

The code to access local data interfaces success!

End!

Guess you like

Origin www.cnblogs.com/gygg/p/12106435.html