-1

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: //able to get the token from $cookies.token

$http.defaults.headers.common['Authorization'] = $cookies.token;

Please Go through the steps:

  1. Tried with complet url : where api.host = 'http://xx.xx.xx.xx1:9000';(external IP)

    return $http({method:'GET', url: api.host+'/aa/734/acd/1860/cd?status=dc',

that time it says error, and the method changed to OPTIONS and the Authorization token has not set.

refer the below image:

enter image description here

And next I changed the api.host = 'localhost' (internal IP) and the code is

return $http({method:'GET', url: '/aa/734/acd/1860/cd?status=dc',

that time the url method is GET, but since the IP is internal it is pointing to my machine. and the Authorization token also set. please refer the below image

Internal IP

When I point to my machine the Authorization token is set, but when I point to external IP it is setting the Method as OPTIONS and the Authorization token is not set.

Any idea from any one.

Thanks in advance.

RONE
  • 5,033
  • 8
  • 33
  • 68
  • possible duplicate of [AngularJS performs an OPTIONS HTTP request for a cross-origin resource](http://stackoverflow.com/questions/12111936/angularjs-performs-an-options-http-request-for-a-cross-origin-resource) – Julien Jul 03 '14 at 06:35

1 Answers1

0

This is a CORS request the client will send an OPTIONS message to the server the server will then reply with the origins that are allowed to call it and the headers that are acceptable on the call. You will need to set you server up to reply to the OPTIONS call to allow the Authorization header.

See this link for more info on enabling CORS in your particular environment http://enable-cors.org/index.html

As far as Angular is concerned if the server sends back the correct CORS headers you will not have to do anything.

Jon
  • 4,255
  • 5
  • 44
  • 55