帮助中心

首页 » 拓扑天然气收费系统 » 抄表客户端 » 网络请求超时设置例子
admin - 2020/8/16 16:13:16
https://stackoverflow.com/questions/58966421/dart-http-package-request-timeout




You have two options availabe.

Reduce the timeout on the HttpClient
final client = new HttpClient();
client.connectionTimeout = const Duration(seconds: 10);
This will apply to all request made by the same client. If the request exceeds this timeout, a SocketException is thrown.

Set a per request timeout
You can set a timeout on any Future using the Future.timeout method.

try {
  ..
  final request = await client.get(...);
  final response = await request.close().timeout(const Duration(seconds: 10));
  // more code
} on TimeoutException catch (e) {
  // handle timeout
}






final response = await http.post(Url).timeout(Duration(seconds: 5));
1
查看完整版本: 网络请求超时设置例子