You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用启动时出现Failed host lookup及连接中止问题求助

网络请求异常排查求助:Failed host lookup与连接中断问题

问题现象

  • 部分用户在应用启动加载页面发送HTTP请求时,出现Failed host lookup: 'api.xyz.io'和Software caused connection abort错误
  • 当前采用顺序同步的3步请求流程:检查网络连接 → 初始化用户 → 获取设置
  • 异常场景:
    • 连接检查环节成功后,初始化用户请求抛出Failed host lookup: 'api.xyz.io'错误
    • 少数情况下所有请求均返回成功,但获取设置环节出现卡顿

错误栈信息

初始化用户时的连接中断错误

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Software caused connection abort. Error thrown Init User.
       at IOClient.send(io_client.dart:88)
       at BaseClient._sendUnstreamed(base_client.dart:93)
       at get.<fn>(http_custom.dart:47)
       at ._withClient(http_custom.dart:256)
       at UserController.initUser(userController.dart:33)
       at LoadingScreenState.checkRequirements(loading_screen.dart:172)
       at LoadingScreenState.asyncInits(loading_screen.dart:121)

连接检查时的主机查找失败错误

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Failed host lookup: 'api.xyz.io'. Error thrown Internet connection failed.
       at IOClient.send(io_client.dart:88)
       at BaseClient._sendUnstreamed(base_client.dart:93)
       at get.<fn>(http_custom.dart:47)
       at ._withClient(http_custom.dart:256)
       at ConnectionUtils.isConnected(connection_utils.dart:11)

请求逻辑示例

所有请求的实现逻辑类似,以下是初始化用户环节的代码:

try {
      final url = this.routes.userRoutes.getSettings;

      // Send the request
      final response = await httpCustom.get(
        url,
        headers: await HeaderUtils.authorizedGet(),
      );
      var responseJson = jsonDecode(response.body);

      User user = User.fromJson(responseJson['user']);
      Settings settings = Settings.fromJson(responseJson);
      await storage.write(key: StorageKeys().user, value: user.toString());
      await storage.write(
          key: StorageKeys().settings, value: settings.toString());
      sendSuccesLog(funcName: "initUser");
      return user;
    } catch (e, stack) {
      FirebaseCrashlytics.instance.recordError(e, stack, reason: 'Init User');
      checkNetworkConnection(funcName: "initUser");
      return null;
    }

已尝试的解决方案

  • 配置Android权限:
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
  • 开启明文流量支持:
    android:usesCleartextTraffic="true"
    
  • 使用internet_connection_checker包进行网络状态预检查,但问题仍未解决

内容的提问来源于stack exchange,提问作者Mehmet Kamay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 05:12:20