【发布时间】:2020-11-13 14:08:17
【问题描述】:
我正在调用 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;
}
【问题讨论】:
-
您发送的标头是什么?它是否包含保持活动标题?请张贴标题
-
我没有在标题中发送保持活动状态,发送这个可以解决我的问题。非常感谢
-
我会将其发布为您问题的答案
-
它可能会帮助未来的答案寻求者
-
@LucasAschenbach 我刚刚添加了这个连接头 this.apiHeader['Connection'] = "keep-alive";
标签: api http flutter dart httpexception