AngularJS reads response cookie parameter empty

If I make a request on my server with $ http, I get the following response:

Request URL:http://www.test.tst/login Request Method:GET Status Code:200 OK Request Headersview source Accept:application/json, text/plain, */* Accept-Encoding:gzip,deflate,sdch Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 Connection:keep-alive Cookie:JSESSIONID=349AD3AC797C6AB28121ADA1766FF4A2 Host:www.test.tst 

i is implemented as follows:

 $scope.checkToken = function () { $http({method: 'GET', url: 'http://www.test.tst/login', params: {'action.code': 'LINK', 'linkparameter': $rootScope.token}}). success(function (data, status, headers, config) { console.log($cookieStore.get('JSESSIONID')); }). error(function (data, status, headers, config) { $location.path("/login"); }); } 

can someone tell me why $ cookieStore.get ('JSESSIONID') is always undefined?

The cookie domain matches the domain from which my request comes.

+4
source share
1 answer

You must use the $ cookie service, not the $ cookieStore $ cookie provides access to browser cookies; and $ cookieStore allows you to store and retrieve values.

This means that you will use $ cookies to access the cookies set by the server. $ cookieStore.get () will allow you to access the values โ€‹โ€‹stored in your application using $ cookieStore.set () Just replace $ cookieStore with $ cookie in your code.

+1
source

Source: https://habr.com/ru/post/1500102/


All Articles