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

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

问题描述

我使用 $ HTTP 来进行API调用,这是将一些自定义标题如 X-美孚。不过,我还不能弄清楚如何阅读。在 $ HTTP({...})。成功(功能(数据,状态,头,配置){...})功能,是应该给我所有标题的散列功能,但只显示标题内容类型。有没有办法得到响应头?

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 ?

推荐答案

在自定义标题会在同一个域中可见。然而,对于跨域情况下,服务器必须发送访问控制展露报头:X-美孚,... 头,使自定义页眉可见

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天全站免登陆