nope nope - 1 year ago 78
AngularJS Question

How can I read headers sent from my API with angular?

I have something similar to the following code on

headers: {
'Content-Type': 'application/json'
.then(function (response) {
}, function (response) {
// something went wrong

It works great communicating with my .NET API.
has all of the data my server needs to give me. However we have a new security token that we are passing to the client from the API and we are passing it in back to the client in the packet header. I know that the token is being passed back because I can read it in the packet on the network tab in chrome debugger. However
only contains
content-type:"application/json; charset=utf-8"
It doesn't have what is in the packet. Any one have an idea?

The data is returned from the API like so (C#)

So i would expect
to have a header called
, but it does not. It is however in the packet.

Answer Source

Use the headers variable in success and error callbacks

  success(function(data, status, headers, config) {
    //things to do
  .error(function(data, status, headers, config) {
    //things to do
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download