使用 Angularjs 的 $http 时读取响应头 [英] Reading response headers when using $http of Angularjs

查看:51
本文介绍了使用 Angularjs 的 $http 时读取响应头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 $http 进行 api 调用,该调用会发送一些自定义标头,例如 X-Foo.但是我还不知道如何阅读它们.在 $http({...}).success(function (data, status, headers, config) {...}) 函数内部,headers 是一个函数这应该给我所有标题的哈希值,但它只显示标题 content-type.有没有办法获取响应头?

I am using $http to make an api call which is sending some custom header like X-Foo. However I can't yet figure out how to read them. Inside the $http({...}).success(function (data, status, headers, config) {...}) function, headers is a function that should give me a hash of all headers but it only shows the header content-type. Is there a way to get the response headers ?

推荐答案

自定义标题将在同一域中可见.但是,对于跨域情况,服务器必须发送 Access-Control-Expose-Headers: X-Foo, ... 标头以使自定义标头可见.

The custom headers will be visible in same domain. However, for the crossdomain situation, the server has to send Access-Control-Expose-Headers: X-Foo, ... header to make the custom headers visible.

这篇关于使用 Angularjs 的 $http 时读取响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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