api - Flutter:接收数据时连接关闭

标签 api http flutter dart httpexception

我正在调用 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;
}

最佳答案

Keep-Alive您的请求 header 中的 header 可能丢失,请检查所需的 API header

关于api - Flutter:接收数据时连接关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63061194/

相关文章:

Flutter:TabBarView 移动到选项卡也会重建其他选项卡

javascript - 谷歌地图 JS API 引用网址

linux - 如何从linux api中已知的uid获取用户名?

http - 缺少升级 : Serve both http and ws on netty 4. x

C++ Wininet 自定义 http header

flutter - flutter 中最多有两条线的 fitbox

iphone - 我可以为我的 Web API 使用基于 session 的身份验证吗?

api - GCP 客户端工具的最佳身份验证策略

http - Wildfly 9 http到https

flutter - 如何使用仅包含键的项列表创建新变量