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 ?
$http is an AngularJS service for reading data from remote servers.
While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.
The problem is as follows, $http. get is asynchronous, before the response is fetched, the function returns. Therefore the calling function gets the data as empty string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With