I am encountering a similar problem mentioned in this post: Angularjs set a authorization header
The issue I am facing is the need to include an authorization token in my request headers. I have attempted various methods to achieve this- such as setting $http defaults like so:
app.config(function($httpProvider) {
$httpProvider.defaults.headers.common['Authorization'] = '1234567';
});
and also utilizing this approach:
app.run(function($http) {
$http.defaults.headers.common['Authorization'] = '1234567';
});
Moreover, I tried configuring my requests using a method within my service:
var request = {
method: 'GET',
url: 'my/api/endpoint',
headers: {
'Authorization': '1234567'
}
};
$http(request).then(function(response) {
console.log(response);
});
Despite all these attempts, the headers of my request do not display the desired key-value pair:
Access-Control-Request-Method: GET
Origin: http://localhost:8000
Access-Control-Request-Headers: accept, authorization
Accept: */*
Referer: http://localhost:8000/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
I anticipate seeing something like this in the headers:
Authorization: '1234567'
Unfortunately, that is not happening.
I am working with Angular version 1.4.9 and wonder if this issue is specific to this particular version?
Solved: The resolution for this matter was found in the Apache configuration on the server-side. However, it is important to note that the authorization headers are actually present in the preflight request header rather than the main request, which could explain their absence from the header.