Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular $http headers not working

My client side look like this :

$http(
       {
            method: 'GET',
            url: myConfig.serverUrl + '/getUserId',
            data: '',
            headers: { 'Authorization' : '21321313'},
       });

Server side in Node js and express :

app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type, Authorization');
next();

});

But request not set the Authorization value
OPTIONS /getUserId HTTP/1.1. Host: xxxxx. Connection: keep-alive. Pragma: no-cache. Cache-Control: no-cache. Access-Control-Request-Method: GET. Origin: http://localhost:9000. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36. Access-Control-Request-Headers: authorization. Accept: */*. Referer: http://localhost:9000/. Accept-Encoding: gzip, deflate, sdch. Accept-Language: en-US,en;q=0.8,he;q=0.6.
I have try many ways but none of them work. When i try to to that with postman i get the value so i think my problem in my angular side but i cant figure out what is the problem .

like image 401
Avihay m Avatar asked May 28 '26 16:05

Avihay m


1 Answers

This issue in server side, In "OPTIONS" API call no need to check Authorization

like image 96
Nadeer Ahammed Avatar answered May 30 '26 06:05

Nadeer Ahammed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!