Flutter在iOS设备上发生“连接服务协议错误:HttpException ..."错误 [英] Flutter occurs 'Error connecting to the service protocol: HttpException...' error on iOS device

查看:68
本文介绍了Flutter在iOS设备上发生“连接服务协议错误:HttpException ..."错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于网络连接,我使用 dio 并通过 Connectivity 检查连接状态.

For network connection I use dio and for checking connection state from Connectivity.

在这里,我检查网络状态:

And in here I check network state:

@override
 Widget build(BuildContext context) {

 bloc.checkConnectivity(Connectivity());

 return StreamBuilder(
    stream: bloc.getInitApp,
    builder: (context, AsyncSnapshot<InitApp> initApp) {
      if (initApp.hasData) {
        return prepareMain(initApp.data);
      } else {
        return Center(
          child: CircularProgressIndicator(),
        );
      }
    });
}

checkConnectivity 方法:

checkConnectivity(Connectivity _connectivity) {
 _connectivity.onConnectivityChanged.listen((ConnectivityResult result){
   if (result == ConnectivityResult.mobile ||
       result == ConnectivityResult.wifi) {
       fetchInitApp();
    }
   });
 }

但是最终,App仅在Android设备上运行,而在iOS(Device/Simulator)上发生此错误:

But eventually, App runs just on Android device but on iOS(Device/Simulator) occurs this error :

Error connecting to the service protocol: HttpException: , uri = http://127.0.0.1:1024/ws

我尝试在没有 Connectivity 的情况下调用 Api ,该应用程序运行良好,但仅在Android和iOS中就可以获取数据,但仍然存在问题.

I tried to call Api without Connectivity and the app work as good but with it gets data just in Android and for iOS still there is problem .

它也是通过 Dart http 包发生的.

2019年9月25日

这与代码无关!

问题是系统WiFi连接.

遇到此问题时,请使用此临时解决方案,直到提供完整的解决方案为止:

When you faced with this problem use this temporary solution until a complete solution is provided:

  1. 断开系统WiFi连接
  2. 拔下电话
  3. 将系统重新连接到WiFi
  4. 插入手机
  5. 运行应用程序

推荐答案

只需将您的设备与IDE重新连接,然后重新启动您的IDE,即可正常工作.

Just reconnect your Device with your IDE and restart as well your IDE, after this it will work.

这篇关于Flutter在iOS设备上发生“连接服务协议错误:HttpException ..."错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆