收藏
回答

wx.request请求服务器, 如果服务端下发多个Set-Cookie会导致cookie错误

https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html

这是服务端下发的Response

wx.request 返回的 response.header['Set-Cookie']结果如下

JSESSIONID=6D9A6F819C765192BB22224EFF383891; Path=/api; HttpOnly,user_token=637780ebdbaf677625a1c061833a965fdd366431219fae14ce3xxxxxxf8d5; Domain=.gelonghui.com; Expires=Sat, 20-Mar-2021 17:40:45 GMT; Path=/

如果用Nodejs常用的cookie模块解析如下

user_token 变成了HttpOnly,user_token

回答关注问题邀请回答
收藏

5 个回答

  • 权志坤🐽
    权志坤🐽
    02-26

    MicroMessenger/8.0.47.2560(0x28002FDF) 版本又出现问题了,复现机型: ELS-AN00 OXF-AN00

    MicroMessenger/8.0.47.2560(0x28002F35) 以及之前版本没有这个问题。

    02-26
    有用 1
    回复 1
    • sun
      sun
      02-27
      请问0x28002FDF版本这种问题怎么解决啊
      02-27
      回复
  • 志雄
    志雄
    2020-11-29

    Set-Cookie都是用逗号拼接的,后端服务是用分号分割,无法把JESSIONID解析出来,可以用正则对header["Set-Cookie"]分割,然后再拼接,详情请见我总结的文章。https://blog.csdn.net/czx0132/article/details/110101854

    2020-11-29
    有用 1
    回复 1
    • 远浅
      远浅
      2021-03-23
      绕开的方案肯定有,但是我认为这是微信的问题。
      2021-03-23
      回复
  • 润岩
    润岩
    发表于移动端
    2021-07-17
    ?。 。,? 。,mn:k ljh.llj j; j
    2021-07-17
    有用
    回复
  • 远浅
    远浅
    2020-03-21
    //index.js
    //获取应用实例
    const app = getApp()
    const jssha1 = require("../../miniprogram_npm/miniprogram_npm/js-sha1/index.js")
    Page({
      data: {
        motto'Hello World',
        userInfo: {},
        hasUserInfofalse,
        canIUse: wx.canIUse('button.open-type.getUserInfo')
      },
      // 綁定點擊事件
      bindHi() {
        // 登錄
        wx.login({
          success(sr) {
            // 獲取加密數據
            wx.getUserInfo({
              success(rres){
              
                const code = sr.code;
                const timestamp = ~~(+new Date() / 1000);
                const sign = jssha1(`${timestamp}${code}wxxxxxxxxxxxxxx9ee417aa35ad230`);
                // 我們系統的接口Set-cookie了兩次
                wx.request({
                  url'https://api.xxx.com/we-chat/mini-program/session',
                  method"POST",
                  header:{
                    platform"xxxx"
                  },
                  data: {
                    code,
                    sign,
                    timestamp,
                    iv:rres.iv,
                    encryptedData: rres.encryptedData
                  },
                  success(r){
                    console.log(r.header['Set-Cookie'])
                  }
                },)
              }
            })
          }
        })
        
      },
      //事件处理函数
      bindViewTapfunction() {
        wx.navigateTo({
          url'../logs/logs'
        })
      },
      onLoadfunction () {
        if (app.globalData.userInfo) {
          this.setData({
            userInfo: app.globalData.userInfo,
            hasUserInfotrue
          })
        } else if (this.data.canIUse){
          // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
          // 所以此处加入 callback 以防止这种情况
          app.userInfoReadyCallback = res => {
            this.setData({
              userInfo: res.userInfo,
              hasUserInfotrue
            })
          }
        } else {
          // 在没有 open-type=getUserInfo 版本的兼容处理
          wx.getUserInfo({
            successres => {
              app.globalData.userInfo = res.userInfo
              this.setData({
                userInfo: res.userInfo,
                hasUserInfotrue
              })
            }
          })
        }
      },
      getUserInfofunction(e{
        console.log(e)
        app.globalData.userInfo = e.detail.userInfo
        this.setData({
          userInfo: e.detail.userInfo,
          hasUserInfotrue
        })
      },
    })
    
    
    
    2020-03-21
    有用
    回复
  • 是小白啊
    是小白啊
    2020-03-21

    看下你是怎么写的呢?

    2020-03-21
    有用
    回复 5
登录 后发表内容
问题标签