【问题标题】:can't get cookie using lua-resty-cookie无法使用 lua-resty-cookie 获取 cookie
【发布时间】:2017-04-28 08:26:02
【问题描述】:

我正在尝试在 openresty 项目中使用 lua-resty-cookie。 我很难在一个请求中使用 lua-resty-cookie 方式获取 cookie 密钥。

nginx.conf:

... /testcookie { 本地 ck = 需要“cookie” 本地 mycookie,错误 = ck:new() 如果不是 mycookie 那么 ngx.log(ngx.ERR,错误) return ngx.say("赋值失败:",err) 结尾 本地 ok, err = mycookie:set({ key = "ckey", 值 = "cvalue" }) 如果不行的话 ngx.log(ngx.ERR,错误) return ngx.say("设置失败:",err) 结尾 本地字段,错误 = mycookie:get('ckey') 如果不是字段那么 ngx.log(ngx.ERR,错误) return ngx.say("获取失败:",err) 结尾 return ngx.say('ckey: ',field) } ...

我得到的是“get failed: no cookie found in the current request\x{0a}”

我做错了吗? 感谢您的帮助。

【问题讨论】:

    标签: nginx lua openresty


    【解决方案1】:

    lua-resty-cookie 的 set() 方法设置响应当前请求发送的 cookie(Set-Cookie 标头)。

    get() 方法用于从当前请求(Cookie 标头)中提取 cookie。

    因此,您在响应中设置了 cookie,然后尝试在请求中找到它;-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-19
      • 2022-01-12
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 2019-12-16
      • 2021-05-18
      相关资源
      最近更新 更多