Access to #39;Set-Cookies#39; header in $http(访问$http中的Set-Cookies标头)
本文介绍了访问$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标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:访问$http中的Set-Cookies标头
基础教程推荐
猜你喜欢
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 响应更改 div 大小保持纵横比 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 动态更新多个选择框 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01