Lou*_*ocq 7 javascript cookies http angularjs
我在AngularJS中使用来自客户端的Web RestFUL API.
app.controller('LoginController', [
'$http',
'$cookies',
function($http, $cookies) {
this.credentials = {};
this.http = $http;
this.login = function() {
console.log(this.credentials);
var authdata = btoa(
this.credentials.username +
':' +
this.credentials.password
);
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata;
console.log($http);
var res = $http.post("http://API_NAME/library");
res.success(function(data, status, header){
alert('Successfull func');
console.log($cookies.get('JSESSIONID'));
});
res.error(function(data, status, headers, config) {
console.log('Error Log');
});
};
},
]);
Run Code Online (Sandbox Code Playgroud)
然后,我有这个Http标题响应
Set-Cookie:JSESSIONID=azekazEXAMPLErezrzez; Path=/; HttpOnly
Run Code Online (Sandbox Code Playgroud)
我正在使用ngCookies获取JSESSIONID值,然后在我的浏览器中手动创建它,但我无法访问它.
我已经在StackOverflow中看到了关于此的所有帖子,但它们已被弃用或完全不清楚.
感谢您的关注和帮助.
您无法使用JavaScript获取HttpOnly cookie.这就是HttpOnly旗帜的全部目的.
那就是说,你不应该这样做.cookie应该随同任何请求自动发送到同一台服务器.如果你正在处理跨域XHR请求,设置your_XHR_instance.withCredentials到true包括饼干.