回传会话不保存
问题描述:
我加了Cookie的会话来middleware.json 我想加上id登录会话,并在功能addLead
回传会话不保存
"session": {
"cookie-session": {
"params": {
"name": "id",
"secret": "secret",
"keys": [ "key1", "key2" ],
"httpOnly": "false"
}
}
}
登录使用它:
router.post("/login", function (req, res)
{
req.session.id = req.body.id
req.sessionOptions.id = req.body.id
//...
})
addLead
router.post("/addLead", function (req, res)
{
console.log(req.session.id)
console.log(req.sessionOptions.id)
})
当addLead
我这叫,我得到
不确定
不确定
我测试使用的页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"
integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="
crossorigin="anonymous"></script>
<script>
function log(data)
{
console.log(JSON.stringify(data))
}
$.post("http://localhost:3000/login", { name: "John Smit", id: 15 }, function (data)
{
log(data)
$.post("http://localhost:3000/addLead", {
name: "Anton Berezin", phone: "337225", model: "1234",
mark: "Toyota", yearFrom: "2014", yearTo: "2017"
}, function (data)
{
log(data)
alert(JSON.stringify(data))
})
.fail(function (error)
{
log(error)
})
})
.fail(function(error)
{
alert(JSON.stringify(error))
})
</script>
</head>
<body>
</body>
</html>
答
“Cookie的会话” 应改为“表达会话”。它会给加密的cookie,应该以某种方式解密...