Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My http response contains the headers Authentication (as mentioned here: Authentication:76efbc0946773b62c93e952b502a47acd898200f6f80dc46ac87ffc501c00780) when I inspect the request with the inspector, but a call to headers("Authentication") returns null

return $http({
    method: "GET",
    url: url,
    headers: {
      'Content-Type': "application/json"
    }
}).success(function (data, status, headers, config) {
    console.log(headers("Authentication"));
})

Do you have any idea about what I could be doing the wrong way ?

FYI, i've tried to switch it back to a "promise" way, with .then, and the issue is still the same.

share|improve this question
4  
You probably need to add Access-Control-Expose-Headers to your response from the server to make it accessible - see stackoverflow.com/questions/17038436/… –  Brad Barber Mar 21 at 18:04
    
@BradBarber that's it. Reply if you want to get the bounty. –  GeoffreyB Mar 23 at 15:54

2 Answers 2

up vote 1 down vote accepted
+50

Your code looks good but if it's a CORS request the server needs to include Access-Control-Expose-Headers: {any custom headers} in the response.

There's a previous question/answer with more details: Reading response headers when using $http of Angularjs

share|improve this answer

In success callback put :

console.log(headers('content-type'));
console.log(headers());  // All headers

I think the first line return a result in your cas.
In the seconde, have you got the 'Authentication' ?

The custom headers will be visible in same domain. In crossdomain case, you need to send Access-Control-Expose-Headers: Authentication, ... header from server.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.