Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

connection failed while calling api in flutter

I am connecting api using swagger it is giving excelent result but when hitting api via mobile app it throws error
connection failed: OS Error: Network is unreachable errorno= 101

my api calling code

  var file = await File(filepath).readAsBytes();
  var uri = Uri.parse('http://192.168.18.2:1111/predict');
  // print(url);
  // Create a multipart request
  var request = http.MultipartRequest("POST", uri);
  // Create a multipart file
  var multipartFile = http.MultipartFile.fromBytes(
    'file',
    file,
    filename: filepath.split("/").last,
  );
  // Add the file to the request
  request.files.add(multipartFile);
  try{
    return await request.send();
  }
  catch(e){
    return http.StreamedResponse(Stream.error(e), 404);
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This could be due to a number of issues.

  • Make sure your device is connected,
  • Wifi or data is enabled,
  • your app has permissions,

and if you’re using HTTP instead of HTTPS, on android and iOS you must allow clear text on Android 8 or higher.

Best place to start is to look at logcat while executing the code which will give an idea what is causing the failure. If you’re connecting to local machine from an emulator, you also need to use the 10.0.2.2 address instead.

If you’re connecting on a local network from a real device to a PC, make sure you’re in the same network, firewalls allow your connection .etc. as well.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading