0

I am attempting to GET information from an AWS server using AngularJS. In order to communicate with the server, an "authorization" is required in the header. I am able to accomplish this with Node.js using 'request', but the AngularJS approach fails.

Note that I had to hide the server address and the authorization for obvious reasons.

The failure occurs somewhere in the '$http.GET' portion. The $scope.message value is set and appears correctly, however, the alert() is never called. I have tried several iterations with passing the information as a config string, etc... I have also tried another website outside the network (but it does not have any authorization requirements), and it works.

Any ideas? Anyone else have any issues talking to AWS server with authorization when using AngularJS?

Here is the code:

var myApp = angular.module('displayApp', [])

myApp.controller('httpController', ['$scope', '$http', function($scope, $http){
$scope.message = "HTTP Testing"

$http({method: 'GET', url: 'http://xxxxxxxxxxxxx.compute-1.amazonaws.com/', headers:{authorization: 'xxxxxxx:xxxxxxxuqu+0gTv'}})
.then(function(response){
    alert("Made it through!!");
});


}]);
chanin
  • 9
  • 3
  • There's most likely an error in your console indicating it's a CORS issue – Phil May 24 '16 at 03:38
  • can you check you browser console? are there any errors or messages? – shershen May 24 '16 at 05:59
  • @Phil - You're correct - there is a CORS issue. It caught me off guard as I was able to access another server, and so I thought it was some kind of authentication issue. Of course, now I'm trying to work around the CORS issue. Attempting a $http.jsonp call resulted in a true authentication issue with "Invalid API credentials supplied". I'll keep digging - but thanks for the help. – chanin May 24 '16 at 22:24

0 Answers0