api - 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;
}
解决方案
Keep-Alive
您的请求标头中的标头可能丢失,请检查 API 所需标头
推荐阅读
- windows - 如何从 Windows 批处理文件 (.bat) 触发 Informatica 工作流
- drop-down-menu - JustifyLeft、Right 和 Center 在菜单中添加时在 ckeditor 工具栏中不起作用
- c# - Use TextTransform (tt files) into the Azure Devops pipeline
- python - Regex , 找到句子,都是大写字母
- ios - 在背景中,WebRTC 优惠在 iOS 中不起作用
- javascript - JavaScript Handlebars 没有错误但不起作用
- image - 扩展名重命名后,图像会在网络上工作吗?
- laravel - Laravel Blade 不输出@section('content')?
- python - Pandas 最大行数,前 n 最大
- python - 从相似字符串列表中获取后缀