'SocketException (SocketException: Failed host lookup: 'test' (OS Error: nodename nor servname provided, or not known, errno = 8))

I've looked elsewhere and every site keeps telling me this is effectively an internet connectivity error... But I know that can't be correct.

I'm using Flutter (dart) to program this for iOS (on a Mac). I've tried this on both the iOS simulator and an actual iPhone, and I'm getting the same error. Other calls to the same server work fine.

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;
}

Works fine. In the response body it contains the session_id, and print-screen proves this variable is not empty.

BUT this:

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;
}

Does NOT work. Not entirely sure why. I even tried allowing unsecured data-transmission to the server in the info.plist.

My understanding or expectation is that MAYBE this is because the url I'm requesting doesn't exist on the server? It's the only thing that makes sense to me. If not, then what COULD it be?

Flutter Doctor results:

[✓] 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!


Solution 1:[1]

Make sure you have internet on your emulator or device. Check by opening your internet browser on your emulator or device to see if google.com will display successfully

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1