老师 请问带cookie的跨域请求 是指前端携带cookie发出去的请求吗?可是我用node req.headers.cookie 读取不到前端的cookie(设置了相关的头 前端也加了withcred....) 如何查看携带的cookie 有啥应用场景?
node 端
var express = require('express')
var app = express()
app.all('/textcookie', function (req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000')
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST')
res.header('Access-Control-Allow-Headers', 'X-Requested-With,If-Modified-Since,Cache-Control,Content-Type')
res.header('Access-Control-Allow-Credentials', 'true')
res.header("P3P","CP=CAO PSA OUR");
res.cookie('name', 'tobi', { domain: 'localhost', path: '/', secure: true });
// console.log(req.headers.cookie)
res.send(req.headers.cookie)
})
app.listen(8081)
html端
$.ajax({
type: 'post',
url: 'http://localhost:8081/textcookie',
xhrFields: {
withCredendtials: true
},
crossDomain: true,
success: function (result) {
console.log(result)
}
})