uni-app 微信小程序 图片验证码获取session

因为微信小程序不支持cookie,所以只能手动保存。

h5模式下尝试的可行方案

https://blog.csdn.net/qq_29287973/article/details/78355558

但是微信小程序运行报“ XMLHttpRequest is not a constructor”,暂未找到解决方案。

尝试着用uniapp的下载方法,完美解决。

//获取验证码,同时保存Cookie
uni.downloadFile({
    url: this.GLOBAL.serverSrc +"/login/imgCode" +"?codetime=" +new Date().getTime(), //仅为示例,并非真实的资源
    success: (res) => {
      this.GLOBAL.Cookie = res.header["Set-Cookie"]
      this.verifyCodeSrc = res.tempFilePath
    }
});
//再请求时加上Cookie
uni.request({
  url: this.GLOBAL.serverSrc + '/login/loginCheck', 
  header:{
    'content-type':'application/x-www-form-urlencoded',
    'Cookie':this.GLOBAL.Cookie
   },
原文地址:https://www.cnblogs.com/changlun/p/13162845.html