Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS - $http not sending headers

As the title suggest, I need to pass an authorization token but when I check the network console, I'm getting a 403 because the accept and authorization isn't there. NOTE: I removed my authorization token for this example

$http({
        url: 'http://api.stubhub.com/search/catalog/events/v2?title="san"',
        dataType: 'json',
        method: 'GET',
        data: '',
        headers: {
            "Content-Type": 'application/json',
            "Authorization": 'Bearer {token}'
        }
    }).success(function(response){
        $scope.searchResponse = response;
    }).error(function(error){
        $scope.error = error;
    });

This seems like correct syntax? What's wrong here?

EDIT: added the XHR screenshot

enter image description here

EDIT: 2. Here's my network traffic, HAR via paste bin:

http://pastebin.com/fiFngZSy

like image 806
Garuuk Avatar asked Nov 08 '14 18:11

Garuuk


1 Answers

setting custom headers on XHR requests triggers a preflight request.

I bet you're seeing an OPTIONS request without the Authorization header, and a corresponding response whose Access-Control-Allow-Headers header value is not listing Authorization, or the API doesn't even allow unauthorized OPTIONS requests.

I don't know the stubhub api, but does it return CORS-compliant responses?

like image 167
marco.eig Avatar answered Nov 12 '22 21:11

marco.eig