0

When sending request with header in angulajs. The request is:

$http.get('http://dev.oms.fetchr.us/order/',{
    headers:{
        'Authorization': 'Token ' + token
    }
})

The request is converted to option request. If I remove the authorization token it works as get request, but returns 403 error.

After so much time and reading I got this about preflight requests. https://developer.mozilla.org/en-US/docs/Web/HTTP/Server-Side_Access_Control I also tried with adding headers define here. But results gives error.

If I edit the request in mozilla console and resend the request then it works. And I am able to hit the api.

I also tried this: How does Access-Control-Allow-Origin header work? to allow origin.but as i running on local server.It is not working too.

It is working fine in JQuery. But not with angularjs please help how to send get request in angularjs with express server on cross-origin.

Community
  • 1
  • 1
UDAY SINGH
  • 13
  • 6

1 Answers1

0

For making get request with header use this

          $http({
                "method": "GET",
                "url": url + "",
                "data": '',
                "headers": { 'Authorization': Your Token },
                "Content-Type": "application/x-www-form-urlencoded ;           charset=UTF-8"
            })
Hassan Tariq
  • 730
  • 7
  • 15
  • Try this http://stackoverflow.com/questions/12111936/angularjs-performs-an-options-http-request-for-a-cross-origin-resource – Hassan Tariq Apr 06 '16 at 09:25
  • Have tried. and this article is in need of technical review.and yes it is giving this due to cross-origin.But how to solve it, because it is converting it into preflight request, hence it becomes option request. – UDAY SINGH Apr 06 '16 at 09:29