I working with $http.get
to sent a HTTP request to my web server and retrieve information. I using angular-js version 1.5.8.
This is how my code looks like:
var config = {
headers: {
'Authorization': 'Bearer ' + token
}
};
$http.get('https://myserver.com/v1/result', config).then(function(response)
{
// On success
}, function (resposne)
{
// On error.
var justForTesting = response.headers('content-type'); // return the expected data ("application/json").
var code = response.headers('company-error-code'); // Not returning the expected data (11). Actual value - 'null'
});
My problem is to retrieve the header company-error-code
from the server's response. Other headers are returning their values without any problems.
In order to make sure that the company-error-code
is exists on the server response, I capture the traffic with chrome ("Network" tab) and got this information:
Request URL:https://myserver.com/v1/result
Request Method:GET
Status Code:400
Remote Address:127.0.0.1:8888
Referrer Policy:no-referrer-when-downgrade
Response Headers
access-control-allow-origin:*
cache-control:no-cache
cf-ray:3d3ccee29b756b55-LHR
content-length:101
content-type:application/json; charset=utf-8
date:Wed, 27 Dec 2017 14:00:47 GMT
expires:-1
pragma:no-cache
server:cloudflare-nginx
status:400
x-aspnet-version:4.0.30319
x-powered-by:ASP.NET
company-error-code:11
As you can see, the header company-error-code:11
is exists on the response (last line in the list) but not when I trying to access it from the response.headers('company-error-code')
code.
Why? How to solve it?