访问$http中的Set-Cookies标头 [英] Access to 'Set-Cookies' header in $http

查看:27
本文介绍了访问$http中的Set-Cookies标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AngularJS的新手,堆放在简单的地方。

我运行简单的代码:

$http.post('/api/login/', {"user":"alexey","password":"alexey"})
     .success(function(data, status, headers, config){
         console.log(headers());
     } );

因此在控制台中仅:

对象{Content-type:"应用程序/json"}

但实际的Header包含很多其他值(来自Chrome网络检查员):

HTTP/1.0 202 ACCEPTED
Date: Sun, 12 Oct 2014 17:39:33 GMT 
Server: WSGIServer/0.1 Python/2.7.5
Vary: Accept, Cookie 
X-Frame-Options: SAMEORIGIN
Content-Type: application/json 
Allow: POST, OPTIONS 
Set-Cookie: csrftoken=rNzbxI3QXBoyBS9XaMCdVHmZ32k8VN3c; expires=Sun, 11-Oct-2015 17:39:33 GMT; Max-Age=31449600; Path=/ 
Set-Cookie: sessionid=jxwsm9b5wuelpnr3a00tuwonq0i9sksk; expires=Sun, 26-Oct-2014 17:39:33 GMT; httponly; Max-Age=1209600; Path=/ 

那么,我如何从响应中读取另一个标头,确切地说是Cookie?

推荐答案

出于安全原因,您无法访问来自XMLHttpRequest的响应的Set-Cookie头。AngularJS$http使用浏览器的XMLHttpRequest实现。

4.7.4 The getAllResponseHeaders() method

返回响应中的所有标头,但下列标头除外 其字段名为Set-Cookie或Set-Cookie2。

这篇关于访问$http中的Set-Cookies标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆