200 Response but no JSON Data returned - Restangular issue?

别来无恙 提交于 2019-12-22 08:13:07

问题


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}

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:


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.



来源:https://stackoverflow.com/questions/26809680/200-response-but-no-json-data-returned-restangular-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!