zoukankan      html  css  js  c++  java
  • 微信小程序使用session时注意的问题 --摘抄

    微信小程序使用session时注意的问题

    https://www.cnblogs.com/liuyj-top/p/12910365.html

     微信小程序不能保存Cookie,导致每次wx.request到服务端都会创建一个新的会话(传过去的sessionid会变化),小程序端就不能保持登录状态了。

    一个比较简单的办法就是把服务端response的Set-Cookie中的值保存到Storage中。

    登录成功后,添加Cookie:

    wx.setStorageSync("cookieKey", res.header["Set-Cookie"]);
    

    然后调用接口时,在header中加入:

    'Cookie': wx.getStorageSync('cookieKey')
    

    接口调用由之前的:

    wx.request({
      url: 'test.php',
      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json' 
      },
      success (res) {
        console.log(res.data)
      }
    })
    
    

    变为:

    wx.request({
      url: 'test.php', 
      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json' ,
        'Cookie': wx.getStorageSync('cookieKey')
      },
      success (res) {
        console.log(res.data)
      }
    })
    
  • 相关阅读:
    mysql时间操作函数和存储过程
    puppet foreman
    mysql c haracter
    socket
    socket 网摘
    网络安全
    sqlite3 C接口
    spring 配置文件XSD地址
    programData
    网络安全数据包分析
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/14644772.html
Copyright © 2011-2022 走看看