因為微信小程序不支持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 },