Flutter response.body 为空 [英] Flutter response.body is empty

查看:57
本文介绍了Flutter response.body 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此 API 向此站点发出 http 请求以检索我的数据

I am working with this API where I make an http request to this site to retrieve my Data

https://fantasy.premierleague.com/api/bootstrap-static/

我第一次使用的时候无法检索到任何数据,经过一番研究,我通过一个简单的flutter升级解决了这个问题(我不知道是什么问题或者升级后为什么解决了),然后几天后我在做这个项目,问题又出现了,每次我尝试提出请求时,我的身体都是空的

first time when I used it I couldn't retrieve any data, after some researches I solved the problem with a simple flutter upgrade ( I couldn't know what was the problem or why it was solved after the upgrade ), then after somedays I was working on the project and the problem occurred again and I am getting an empty body every Time I try to make a request

http.get("https://fantasy.premierleague.com/api/bootstrap-static/")

我正在使用这一行获取响应值,然后尝试将其解码为 JSON 值,但发生此错误

I'm using this line to get a Response value and then try to decode it to JSON value but this error happens

exeption occured : FormatException: Unexpected end of input (at character 1)

我已经知道这个错误的发生是因为我试图解码一个空体,但我不明白为什么会发生这种情况

I already know that this error happens because I am trying to decode an empty body, but I can't understand why this is happening

注意:我尝试了多个其他 API 网址,它们都可以正常工作!!

推荐答案

所以我最终切换到 flutter master 并且代码运行良好,我仍然不知道为什么它不能在 stable 上运行但在 master 上运行.无论如何,如果有人遇到此问题,只需切换到 master 即可,它应该可以正常工作.谢谢.

So I end up switching to flutter master and the code worked perfectly, I still don't know why it doesn't work on stable but works on master. anyway if anyone is having this issue just switch to master and it should work fine. Thanks.

这篇关于Flutter response.body 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆