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
   },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM