200响应,但未返回JSON数据-再次出现问题? [英] 200 Response but no JSON Data returned - Restangular issue?
问题描述
使用矩形和存根集线器API.我可以在firefox restclient上点击该API,并获得包含所有JSON数据的响应正文.
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.
但是在我的应用程序中,我得到了200个但没有响应的正文...内容长度甚至表明存在某些内容
But in my app, I get a 200 but no response body... the content length even says something's there
尽管api表示您只需要GET/URI端点和授权:Bearer {token}
albeit the api says you just need GET/URI endpoint and Authorization: Bearer {token}
这是我的矩形配置
'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
});
}]);
这是我的控制器
$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.
推荐答案
我弄清楚了问题所在,也可能是您遇到的问题.
您的响应的Content-Type可能类似于application/javascript
而不是application/json.
这就是为什么它不是被Restangular捕获,而是被浏览器或REST客户端捕获的原因.
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.
这篇关于200响应,但未返回JSON数据-再次出现问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!