ios - SocketException(SocketException:主机查找失败:'test'(操作系统错误:提供节点名或服务名,或未知,errno = 8))
问题描述
我在其他地方看过,每个网站都一直告诉我这实际上是一个互联网连接错误......但我知道这不可能是正确的。
我正在使用 Flutter (dart) 为 iOS 编程(在 Mac 上)。我在 iOS 模拟器和实际的 iPhone 上都试过这个,我得到了同样的错误。对同一服务器的其他调用工作正常。
Future<Map> createTrip() async {
http.Response response = await http.post(
url,
headers: <String, String>{'authorization': basicAuth},
body: {'user_phone': user_phone, 'locationId1': locationId1, 'locationId2': locationId2},
);
info = jsonDecode(response.body);
sessionID = info['session_id'];
print (info['session_id']);
return info;
}
工作正常。在响应正文中,它包含 session_id,并且打印屏幕证明此变量不为空。
但是这个:
Future<Map> getServerData(sessionID) async {
url = url + sessionID; //. <--- adding sessionID to end of a url-address
http.Response response = await http.get(
url,
headers: <String, String>{'authorization': basicAuth},
);
Map data = jsonDecode(response.body);
return data;
}
不工作。不完全确定为什么。我什至尝试在 info.plist 中允许不安全的数据传输到服务器。
我的理解或期望是,这可能是因为我请求的网址在服务器上不存在?这是唯一对我有意义的事情。如果不是,那会是什么?
颤振医生结果:
[✓] Flutter (Channel master, v1.14.2-pre.54, on Mac OS X 10.15.2 19C57, locale
en-CA)
• Flutter version 1.14.2-pre.54 at /Users/iosdev/Developer/flutter
• Framework revision da0bfd1c93 (32 hours ago), 2020-01-21 05:59:07 -0500
• Engine revision c15efb9231
• Dart version 2.8.0 (build 2.8.0-dev.3.0 f910a7575f)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/iosdev/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (2 available)
• Phillip’s iPhone • 52a4fba45a6767b88e4dddd881201205138cac0e • ios • iOS
13.3
• iPhone 11 Pro Max • 2F6FBCBE-CC96-4044-84FA-0DE39E441830 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
• No issues found!
解决方案
确保您的模拟器或设备上有互联网。通过在您的模拟器或设备上打开您的 Internet 浏览器来检查 google.com 是否会成功显示
推荐阅读
- c++ - 使用 PsLookupProcessByProcessId 获取进程 PID
- java - Mongo upsert 性能问题
- angular - 如何在角度变量中设置jquery数据?
- apache-camel - Camel 3 中的 Camel 代理支持
- datepicker - katalon 记录器在运行时无法读取日期选择器
- javascript - 在导出函数中调用方法或 useState setState
- android - 如何检测图像是垂直还是水平
- linux - 使用 epoll 监听只读 sysfs 文件
- javascript - 如何用数组替换 javascript url?
- opentracing - 如何在正在运行的应用程序中启用和禁用跟踪