跨域请求时未设置 cookie。我的服务器在 localhost:8000 中运行,客户端在 localhost:9000 中运行。服务器nodejs/express上的cors设置是
app.use(function(req, res, next) {
console.log(req.method);
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Cache-Control, Authorisation");
if (req.method === 'OPTIONS') {
return res.send(200);
} else {
return next();
}});
客户端使用Angularjs,cors配置为
SelappsAdmin.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}])
快车上
app.use(require('cors')({
origin: function (origin, callback) {
callback(null, origin);
},
credentials: true
}));
在有角度的
$httpProvider.defaults.headers.common['X-Requested-With'] ='XMLHttpRequest';
$httpProvider.defaults.withCredentials = true;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)