小程序安卓手机,无法执行wx.request
开发者工具和IOS端表现:
安卓真机调试表现:
查看network并没有没有访问api
代码片段:
/** * 上传识别数据 */clockIn: function () { var that = this, data={}; _request.postRequest(_api.clockIn.clockIn, data).then(function(res){ //逻辑代码 }).catch(function(res){ console.log('catchError',res) }); }, |
/** * PUT类型的网络请求 */ putRequest(url, data, header = this._header) { return this.requestAll(url, data, header, 'PUT') } /** * POST类型的网络请求 */ postRequest(url, data, header = this._header) { return this.requestAll(url, data, header, 'POST') } /** * 网络请求 */ requestAll(url, data, header, method) { return new Promise((resolve, reject) => { wx.request({ url: url, data: data, header: header, method: method, success: (res => { console.log('访问接口',res); if (res.statusCode === 200) { //200: 服务端业务处理正常结束 console.log({'数据':data,"地址":url,"结果":res.data}); resolve(res) } else { //其它错误,提示用户错误信息 if (this._errorHandler != null) { //如果有统一的异常处理,就先调用统一异常处理函数对异常进行处理 this._errorHandler(res) } reject(res) } }), fail: (res => { console.log('访问api失败,失败原因:',res); if (this._errorHandler != null) { this._errorHandler(res) } reject(res) }), complete:(res=>{ console.log('complete',res); }) }) }).catch(function (res) { console.log(res); }) } |
