Flutter SocketException: OS Error: No route to host, errno = 113, address = xxxx, port = 42376

8,835

SOLVED !!!!

if you want access api from external device so you need to be at same network with local host to do that click on this link to help you connect to local host.

How can I access my localhost from my Android device?

  • If you run Xammp as virtual machine it will host your files with different ip like (192.168.64.2) so to make it host on local host you need activate port forwarding rules from : open

Xammp -> Network -> enable ;

hope this help you .

Share:
8,835
Ichsan Fathurrochman
Author by

Ichsan Fathurrochman

Updated on December 17, 2022

Comments

  • Ichsan Fathurrochman
    Ichsan Fathurrochman over 1 year

    I received this error

    Unhandled Exception: SocketException: OS Error: No route to host,
    errno = 113, address = (my url api), port = 42392
    

    while trying to access it with this code:

    final String basicAuth = 'Basic ' + base64Encode(utf8.encode('$authUsername:$authPassword'));
    final String _grantType = "password";
    
    http.Response response = await http.post(
      Uri.encodeFull("this is my url api"),
      headers: <String, String>{
        "authorization": basicAuth,
        'content-type': 'application/x-www-form-urlencoded',
      },
      body: {
        "username": username,
        "password": password,
        "grant_type": _grantType,
      },
    );
    

    I've tried the URL using postman and work perfectly, did I write it correctly? I'm not sure about placing authorization basic auth code

  • Ichsan Fathurrochman
    Ichsan Fathurrochman about 4 years
    problem is solved already, turns out it was because i got to connect on wrong wifi and the api that i want to connect is in local network
  • Abdul raheem
    Abdul raheem almost 2 years
    my network is also same still facing the same issue
  • Abdul raheem
    Abdul raheem almost 2 years
    Stuck with this issue since morning😭😭 i am using nodejs with mongoodb for my flutter project