0

I'm making a request to my Node.js server using the Postman plugin for Chrome. In my headers I have a field called Cookie and it's populated with my AuthSession cookie like so:

AuthSession="somekeyhere";

I've tried using a Set-Cookie field as well, to be honest I don't really know the difference between the two.

Here is my code that's supposed to receive the cookie, but it doesn't seem to be working.

exports.add = function(req, res) {
    console.log(req.cookies['AuthSession']);
}

It keeps logging undefined. Obviously I'm doing something wrong, I'm just not sure what.

4

1 回答 1

1

首先验证设置 cookie 是否有效。使用下面的函数并加载两次。第一次它会显示你现有的cookie。第二次它会告诉你它第一次设置的cookie。

exports.add = function(req, res) {
    console.log(req.cookies['AuthSession']);
    res.cookie('AuthSession', 'somekeyhere');
    res.send("<html><body>Hello world</body></html>");
}
于 2013-05-09T17:17:24.780 回答