为什么我不能从标题中提取cookie? AngularJS + dJango

时间:2016-03-01 22:57:19

标签: angularjs django cookies http-headers csrf

我试图从标题中获取cookie值,但它返回undefined。

使用$ cookies模块。

服务

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

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

    return {

        getEvents : function(params) {

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

}]);

控制器:

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

响应标题

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=/

我无法获得csrftoken cookie。所以我可以用它在django端点上发送帖子请求。

0 个答案:

没有答案