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.
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