为什么在接口中写了set-cookie却不生效
来源:3-7 cookie和session
edgex
2018-06-21
我想模拟一种登录鉴权的场景。
代码是这么写的
index.html中部分代码
<script>
var dom = document.getElementById('content');
fetch('/login').then( (res)=> res.text() ).then( (data) => {
dom.innerHTML = data;
})
</script>server.js中部分代码
http.createServer((req, res) => {
if (req.url === '/') {
const html = fs.readFileSync('index.html', 'utf8')
res.writeHead(200, {
'content-type': 'text/html',
})
res.end(html)
}
if (req.url === '/login') {
res.writeHead(200, {
'Set-Cookie': 'auth=012390219032139'
})
res.end('success');
}
}).listen('8888')这是第二次请求接口的network截图

问题
为什么第二次请求/login,request里不带cookie?
如果使用/login接口设置一次cookie,如何让以后所有请求的其他接口都带cookie值?
写回答
1回答
-
edgex
提问者
2018-06-21
是fetch的问题。
012018-06-25
相似问题