dio flutter中的connectTimeout参数是什么

What is connectTimeout parameter in dio flutter

我正在使用 DIO 包 here。我的问题是我无法清楚地理解 dio 选项中的“connectTimeout”参数。一开始我以为是这个时间,如果没有网络连接,它会在指定的时间内尝试连接到API。

文档如下:

/// Timeout in milliseconds for opening url. /// [Dio] will throw the [DioError] with [DioErrorType.CONNECT_TIMEOUT] type /// when time out.

我通过在禁用互联网的情况下调用下面的脚本来测试我的假设

    Dio dio = new Dio();
    Response response;

    dio.options.connectTimeout = 50000;
    dio.options.receiveTimeout = 30000;
    dio.options.sendTimeout = 30000;

    response = await dio
        .get(GeneralStringUtil.someGetAPI);

我的日志中立即出现以下异常:

DioError [DioErrorType.DEFAULT]: SocketException: Failed host lookup: xyz.com

所以我的假设是错误的。这个“connectTimeout”参数是什么?

你设置了 50000 miliSeconds 的限制,所以 dio 将尝试 50000 miliSeconds 的 http 调用,如果它在此期间无法连接到服务器,它们将显示异常,你增加的时间越长dio 将尝试连接