Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve WeChat Mini Programs's sessionid inconsistency?

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

这篇文章主要讲解了"微信小程序sessionid不一致怎么解决",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"微信小程序sessionid不一致怎么解决"吧!

问题

由于小程序端两次请求的 sessionid 不一致, 导致后端无法取得 session

解决办法

在登录时获取sessionid

//第一次请求登录接口时保存到sessionid中success: function (res) { wx.hideLoading(); wx.removeStorageSync('sessionid');//每次登录时清楚缓存 if (res.data.code == "0000") { if (res.data.data.roleList[0].value =='student'){ wx.showToast({ title: '登录成功', icon: 'success', duration: 1000 }) wx.setStorageSync('sessionid', res.header['Set-Cookie']); //保存Cookie到Storage } } else { wx.showToast({ title: '登录失败', icon: 'none', duration: 2000 }) } },

在后面进行页面的请求时,在请求头header里加上你存储的这个Set-Cookie的值

wx.request({ url: 'https://xxxx/examResult/selectWxListStudentStudyStatistic', method: 'post', header: { 'content-type': 'application/x-www-form-urlencoded',//解决请求不到数据 'cookie': wx.getStorageSync("sessionid")//读取sessionid,当作cookie传入后台将PHPSESSID做session_id使用 }, success: function (res) { wx.hideLoading();//去掉loading }, fail: function (e) { wx.showToast({ title: '服务器出现错误', icon: 'none', duration: 2000 }) } })感谢各位的阅读,以上就是"微信小程序sessionid不一致怎么解决"的内容了,经过本文的学习后,相信大家对微信小程序sessionid不一致怎么解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report