Why cant i extract the cookie from the header? AngularJS + dJango

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:33:14

问题


Im trying to get the cookie value from the header but it returns undefined.

Using $cookies module.

Service:

socialMarkt.factory('homeService', ['$http', function($http){

    var apiAddress = "http://server.apigoeshere.io:8000/s/first/";

    return {

        getEvents : function(params) {

            return $http.get(apiAddress, {params});
        }
    }

}]);

Controller:

homeService.getEvents({"page":"1"}).then(
        function(response){
            $scope.events = response.data.events;
            console.log($cookies.get('csrftoken')) //undefined;
        });

Response Header

HTTP/1.1 200 OK
Server: gunicorn/19.4.5
Date: Tue, 01 Mar 2016 22:47:55 GMT
Connection: close
Transfer-Encoding: chunked
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Set-Cookie: csrftoken=HN8Zqh7dup4DnnZInd25WT25DEQ3m5rM; expires=Tue, 28-Feb-2017 22:47:55 GMT; Max-Age=31449600; Path=/
Set-Cookie: sessionid=39aq2f5d06ianw65vgm3hmf37ctlbj3l; expires=Tue, 15-Mar-2016 22:47:55 GMT; httponly; Max-Age=1209600; Path=/

I cant get the csrftoken cookie. so i can use it to send post request on a django endpoint.

来源:https://stackoverflow.com/questions/35735279/why-cant-i-extract-the-cookie-from-the-header-angularjs-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!