我在AngularJS中使用我客户端的Web RestFUL API。获取JSESSIONID值并在AngularJS中创建Cookie
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');
});
};
},
]);
然后,我有这个HTTP首部的响应
Set-Cookie:JSESSIONID=azekazEXAMPLErezrzez; Path=/; HttpOnly
我使用ngCookies得到JSESSIONID值,然后在浏览器中手动创建
,但我不能访问它。
我已经在StackOverflow中看到了关于此的所有帖子,但它们已被弃用或完全不清楚。
感谢您的关注和帮助。
为什么你需要在Angular中访问JSESSIONID?该cookie被标记为HttpOnly,即它不能在JS中访问。 –
我没有得到自动处理cookie JSESSIONID的发送。 我以为我不得不手动去做。 评论帮助我理解了这一点。问题解决 –