这个应该是setStorageSync过时的问题吧,说这些有的没的
开启远程调试时 经常报SDK:setStorageSync:fail这个错误APP-SERVICE-SDK:setStorageSync:fail Error: Failed To Send Sync;at App log function;at api request success callback function Error: APP-SERVICE-SDK:setStorageSync:fail Error: Failed To Send Sync at new t ([publib]:7:10135) at Oo ([publib]:8:6460) at Object.Wo.(anonymous function) [as setStorageSync] ([publib]:8:7826) at Object.([publib]:6:29338) at Function.([publib]:14:10718) at Object.([publib]:5:24761) at success (weapp:///app.js:46:20) at Function.function.a.(anonymous function) ([publib]:6:29081) at Object.success ([publib]:4:4154) at X.([publib]:6:24667) [代码]getOpenId: [代码][代码]function[代码] [代码]getOpenId(cb) {[代码][代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.hideShareMenu();[代码][代码] [代码][代码]if[代码] [代码]([代码][代码]this[代码][代码].globalData.openId) {[代码][代码] [代码][代码]this[代码][代码].log([代码][代码]this[代码][代码].globalData.openId, [代码][代码]'缓存'[代码][代码]);[代码][代码] [代码][代码]cb([代码][代码]this[代码][代码].globalData.openId);[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]//调用登录接口[代码][代码] [代码][代码]wx.login({[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码]success(res) {[代码][代码] [代码][代码]var[代码] [代码]code = res.code;[代码][代码] [代码][代码]that.log(code, [代码][代码]'实时获取到的 code'[代码][代码]);[代码][代码] [代码][代码]//通过code换取openid[代码][代码] [代码][代码]wx.request({[代码][代码] [代码][代码]url: that.globalData.remoteUrl + [代码][代码]'/api/login'[代码][代码],[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]_ajax: 1,[代码][代码] [代码][代码]code: code[代码][代码] [代码][代码]},[代码][代码] [代码][代码]method: [代码][代码]'POST'[代码][代码],[代码][代码] [代码][代码]header: {},[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码]success(res) {[代码][代码] [代码][代码]that.log([代码][代码]'getOpenid'[代码][代码], res);[代码][代码] [代码][代码]if[代码] [代码](res.data.code == 1) {[代码][代码] [代码][代码]that.globalData.openId = res.data.data.xcxopenid;[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'openId'[代码][代码], res.data.data.xcxopenid);//报错代码位置[代码][代码] [代码][代码]if[代码] [代码](res.data.data.token) {[代码][代码] [代码][代码]wx.setStorageSync([代码][代码]'token'[代码][代码], res.data.data.token);[代码][代码] [代码][代码]that.globalData.token = res.data.data.token;[代码][代码] [代码][代码]}[代码][代码] [代码][代码]that.log(that.globalData.openId, [代码][代码]'实时获取到的 openid'[代码][代码]);[代码][代码] [代码][代码]cb(that.globalData.openId);[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]cb();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码]fail(res) {[代码][代码] [代码][代码]that.wlanchaoshi(res);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码]
2018-10-25因为地址是用的我们本地的域名,所以直接粘到这里里 wx.uploadFile({ url: 'http://********', // filePath: that.data.Images[0].url, filePath: that.data.Images[0].url, name: 'uploadfile_ant', formData: { "info": "aaaa", "longti": "0.0", "lati": "0.0", "prio": "aa", "username": "aaaa", }, header: { "Content-Type": "multipart/form-data", "Cookie":"JSESSIONID=wKgByBroW8_nOOyBu8CynkHZs3MbTA2vYoEA" }, }) 这样是可以执行的,但是图片地址不能为空 但是 wx.request({ url: 'http://******', data: { "info": "aaaa", "longti": "0.0", "lati": "0.0", "prio": "aa", "username": "aaaa", }, method: "POST", header: { "Content-Type": "multipart/form-data", "Cookie": "JSESSIONID=wKgByBroW8_nOOyBu8CynkHZs3MbTA2vYoEA" }, success: function (res){ console.log(res); }, fail: function () { }, complete: function () { } }) 这样cookie是传不过去的。
request 无法使用multipart/form-data来请求在微信小程序中,http请求为multipart/form-data在wx.request 的请求中Cookie一直是失效,只能通过uploadfile来完成这样的请求,但是只是想传递Content-Type为multipart/form-data的String类型(不带图片)又无法传递。 header: { "Content-Type": "multipart/form-data", "Cookie": "JSESSIONID=wKgByBroW8_nOOyBu8CynkHZs3MbTA2vYoEA" } 这样 这到底是什么毛病。应该怎么做,求解答。
2018-10-25