200 Response but no JSON Data returned - Restangul

2019-05-05 13:47发布

Using restangular and the stub hub api. I can hit this API on the firefox restclient and get a response body back with all the JSON data.

But in my app, I get a 200 but no response body... the content length even says something's there

albeit the api says you just need GET/URI endpoint and Authorization: Bearer {token}

screen shot 2014-11-07 at 11 01 40 am

screen shot 2014-11-07 at 11 01 59 am

Here's my restangular config

'use strict';
angular.module('myapp')
.config(['RestangularProvider', function(RestangularProvider){
    RestangularProvider.setBaseUrl('https://api.stubhub.com/');
    RestangularProvider.setDefaultHeaders({
        Accept: 'application/json',
        Authorization: 'Bearer 198u2190832190831432742(notreallymytoken)'
    });
    RestangularProvider.setDefaultHttpFields({
        withCredentials: false
    });
}]);

and here's my controller

$scope.searchEvents = function(){
    Restangular.one('search/catalog/events/v2?title="san francisco"').get().then(function(response){
        $scope.searchResponse = response;
    }, function(response){
        console.log("something went wrong");
    })
}

How can I begin to debug? I want to keep using restangular so hopefully I can get around this somehow.

1条回答
太酷不给撩
2楼-- · 2019-05-05 14:21

I figured out what the problem was and could be in your case too. The Content-Type for your response would have probably been something like application/javascript and NOT application/json. Which is why it is not caught by Restangular but by browser or REST clients.

查看更多
登录 后发表回答