200响应,但未返回JSON数据

编程入门 行业动态 更新时间:2024-10-09 23:18:01
本文介绍了200响应,但未返回JSON数据-再次出现问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用矩形和存根集线器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('api.stubhub/'); 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数据

本文发布于:2023-10-27 23:52:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但未   数据   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!