How to send Username and APIKey using $http?


#1

Hi all,

I’m using the api service from this website (flightaware.com). The API is called using url like this:

http://YOUR_USERNAME:YOUR_API_KEY@flightxml.flightaware.com/json/FlightXML2/InFlightInfo?ident=AA100

I got this error “***401 (Authorization Required)***” when trying to get the response using $http

Here is my code:

var url = "http://MY_USERNAME:MY_API_KEY@flightxml.flightaware.com/json/FlightXML2/InFlightInfo?ident="+ident;
      console.log("URL: "+ url);
      var deferred = $q.defer();

  setTimeout(function() {
    deferred.notify('About to run.');
    
   
   $http.get(url).then(function(result){ 
         
            console.log("#####_LOCATION_#####: "+result.data);
            deferred.resolve(result.data);

        }, 

        function(err) {
             deferred.reject(err);
         }

   );


  }, 600);


  
  return deferred.promise;

  }

Please help …