如何解决 SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7) [英] How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)
问题描述
每当我在大约 20 秒后尝试进行 http 调用时,我都会在控制台中收到以下错误:
E/flutter (8274): [ERROR:flutter/shell/common/shell.cc(184)] Dart 错误:未处理的异常:E/flutter(8274):SocketException:主机查找失败:'flutter-project-xxxxx.firebaseio.com'(操作系统错误:没有与主机名关联的地址,errno = 7)
我通过应用程序 http 包调用的每个方法和每个路由都会发生此错误.
我正在 Windows 上开发 Flutter 应用程序,使用来自 Android Studio 的 AVD 虚拟设备.
版本:
http: ^0.12.0+1颤振:1.0
案例:
在家中或通过我的手机进行网络共享:虚拟设备的每个部分都可以正常连接
来自我的工作网络(在防火墙后面):
只有使用 Android 网页视图,我才能毫无问题地浏览互联网(我什至可以调用相同的 url,我在代码中使用并且可以正常工作).在虚拟设备中使用任何其他应用程序(Chrome、Google Play、ecc...)时出现连接错误,特别是在测试我的应用程序时出现SocketException".
来自该应用的来电有什么区别?有没有办法以与 webview 中的调用相同的方式路由我的应用程序调用?
谢谢!
添加internet 权限 不仅仅是一个解决方案.
您还必须确保您在线,无论是移动设备还是模拟器
确保您在线,无论是移动设备还是模拟器
确保您已在应用的 android/app/src/main/AndroidManifest.xml
中授予互联网权限
Whenever I try to do an http call after about 20 seconds I get in the console the following error:
E/flutter ( 8274): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 8274): SocketException: Failed host lookup: 'flutter-project-xxxxx.firebaseio.com' (OS Error: No address associated with hostname, errno = 7)
This error happens for every method and every route I call through the app http package.
I'm developing a flutter app on Windows, using an AVD virtual device from Android Studio.
Versions:
http: ^0.12.0+1
flutter: 1.0
Cases:
From home or though tethering from my phone: connectivity works fine on every part of the virtual device
From my work network (behind the firewall):
Only with Android Web View, I can browse the internet without any problem (i can even call the same url, I use in the code and it works). I get a connection error when using any other application (Chrome, Google Play, ecc...) in the virtual device, and specifically the "SocketException", when testing my app.
What is the difference between the calls coming from that app? Is there a way to route my app calls the same way as the ones in the webview?
Thanks!
Adding internet permission is not only a solution.
You also have to make sure that you are online whether it is mobile or emulator
Make sure you are online whether it is mobile or emulator
Make sure you have given internet permission in your app's android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
这篇关于如何解决 SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!