Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - set HTTP header for GET request

May be this is a general issue, which can be available on internet, But what I got is here.

Adding a custom header to HTTP request using angular.js

So I followed the same, and changed the code to

Setting header

 var config = {headers:  {
                'Authorization': 'XXXYYY token="xxxxxxxx", realm="dash-api"',
                "X-Testing" : "testing"
                }
            };

The get request call:

return $http.get(api.host+'/agn/12/adv/1860/cam?status=1', config).then(function (response) {
                    return {
                        status:"success",
                        data:response.data.data.active
                    };
                }, function (error) {
                    return {
                        status:"error",
                        data:error
                    }
                });

As you can see the request are going in method type OPTIONS, and the Authorization token is not set in the request.

Please help me in this issue, as I am struggling from two days.

Thanks a lot.

enter image description here

like image 268
RONE Avatar asked Jul 03 '14 01:07

RONE


1 Answers

I think if you take a look at the link you refer to, you are getting the same issue as the author and the author of that post did state that it was a CORS issue - the server he was communicating with didn't support CORS, he confirms this in his comment on his own post.

As for why you are getting an OPTIONS request, this is because CORS makes a "pre-flight" request to the server to establish if CORS is going to be supported, before it will make the actual request.

like image 97
Rob Wilson Avatar answered Oct 21 '22 14:10

Rob Wilson