Flutter http [GET] [200]为空,无法获得确切的API

时间:2020-11-02 19:53:08

标签: api flutter http

回到旧项目(从Win切换到Mac)后,我无法运行它,因为http到https://fantasy.premierleague.com/api/bootstrap-static/返回空,状态代码为200。我尝试了其他API,并且可以正常使用相同的代码。我试过Dio包,结果是一样的。

通话代码。

static const baseUrl = 'https://fantasy.premierleague.com/api';

Future<BootstrapData> getBootstrapData() async {
  var response = await http.get('$baseUrl/bootstrap-static/');
  return BootstrapData.fromJson(json.decode(response.body));
}

此外,我还通过电话重新安装了该应用程序(由于从Win生成而失败),并升级了flutter版本(也尝试降级)。

我可以通过浏览器或邮递员访问URL。任何想法可能导致这种行为吗?可能是环境配置有问题吗?我没有主意...

编辑: 我不确定这是否有帮助,但是我的应用程序的响应标头(与Postman或直接浏览器的请求标头不同):

{ 
  x-timer: S1604428734.150394,VS0,VE0, 
  x-served-by: cache-bma1625-BMA, 
  connection: close, 
  accept-ranges: bytes, 
  date: Tue, 03 Nov 2020 18:38:54 GMT, 
  content-length: 0, 
  via: 1.1 varnish, 
  retry-after: 0, 
  content-type: application/json, 
  x-cache-hits: 0, 
  x-cache: MISS, 
  server: Varnish
}

1 个答案:

答案 0 :(得分:0)

尝试将Future设置为HTTP响应类型,然后在响应完成后将其类型设置为bootstrapdata