小编Nab*_*faq的帖子

Flutter:接收数据时连接关闭

我正在调用 post API,有时我从服务器得到响应,有时我收到异常Connection closed while receiving data。两种情况下的请求都相同,并且根据后端服务器日志,发送了响应,但我没有收到。我在模拟器和实际设备中都有这个问题。

try {
  final result =
      await http.post(url, body: encodedBody, headers: apiHeader);
  Map<String, dynamic> response = json.decode(result.body);

  print("Response: $response");

  return response;
} catch (error) {
  Map<String, dynamic> response = Map<String, dynamic>();
  response['success'] = false;
  response['message'] = error;
  return response;
}
Run Code Online (Sandbox Code Playgroud)

api http httpexception dart flutter

8
推荐指数
1
解决办法
5594
查看次数

标签 统计

api ×1

dart ×1

flutter ×1

http ×1

httpexception ×1