使用 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.