Dio: 设置了超时时间为10秒,但10秒后并没有返回超时的错误或其他错误

Created on 19 Sep 2018  ·  2Comments  ·  Source: flutterchina/dio

Steps to Reproduce

 options = Options( 
      baseUrl: "https://www.xx.com/api",

      connectTimeout: 10000,

      receiveTimeout: 3000,
      headers: {},
    );
    dio = new Dio(options);


print('get请求启动! url:$url ,body: $data');
    Response response;
    try {
      response = await dio.get(
        url,
        data: data,
        cancelToken: cancelToken,
      );
      print('get请求成功!response.data:${response.data}');
      return response.data;
    } on DioError catch (e) {
      if (CancelToken.isCancel(e)) {
        print('get请求取消! ' + e.message);
      }
      print('get请求发生错误:$e');
    }
    return null;

Most helpful comment

dio超时直接使用的是HttpClient的超时,connectTimeout的意思是建立连接的超时时间,如果10秒内建立连接成功了,则connectTimeout的超时就不会触发了。接下来接收数据时则会开始receiveTimeout的超时记时,receiveTimeout的含义是两次接收到数据的间隔超时,如果网络只是比较慢,则数据就会一点点传输,除非超过receiveTimeout

:octocat: From gitme Android

All 2 comments

dio超时直接使用的是HttpClient的超时,connectTimeout的意思是建立连接的超时时间,如果10秒内建立连接成功了,则connectTimeout的超时就不会触发了。接下来接收数据时则会开始receiveTimeout的超时记时,receiveTimeout的含义是两次接收到数据的间隔超时,如果网络只是比较慢,则数据就会一点点传输,除非超过receiveTimeout

:octocat: From gitme Android

我也遇到了相同的问题 connectTimeout超时没有即时返回错误或res

Was this page helpful?
0 / 5 - 0 ratings