[英]Cookie parser's "res.cookie('cookieName', {cookieData}); doesn't set a cookie
I'm working on with nodeJs , and ExpressJs . 我正在处理nodeJs和ExpressJs 。
recently, I had this issue : 最近,我遇到了这个问题:
after res.cookie('cookieName', {cookieValue});
在res.cookie('cookieName',{cookieValue})之后; my req.cookies is still empty.
我的req.cookies仍然是空的。
Here is my code [when I set the cookie] 这是我的代码[设置Cookie时]
res
.cookie('vendor', vendor,
{
expires: moment().add(CONF.server.tokens.expiration.short, 'h').toDate(),
httpOnly: false,
});
And here is my code [when i want to get this cookie] 这是我的代码[当我想获取此Cookie时]
await request({
method: 'POST',
baseUrl: process.env.SERVER,
uri: '/users/shops/' + req.cookies.vendor.vendorId + '/credits',
headers: {
'Authorization': 'Bearer ' + req.cookies.access_token,
'User-Agent': req.get('User-Agent'),
'X-Forwarded-For': req.ip
},
json: true,
body: {
packs: req.body.packs,
stripeToken: req.body.stripeToken
}
});
When I use Visual studio code's debugger, here is what i got, an empty object : debugger screenShot
当我使用Visual Studio代码的调试器时,这是我得到的一个空对象: 调试器screenShot
Thanks a lot for your precious help, have a nice day/night. 非常感谢您的宝贵帮助,祝您白天/晚上都愉快。
我认为您应该更改“ httponly = true”并通过res.send()发送响应
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.