androidflutterpostman

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


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


Solution

  • 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?

    Xammp -> Network -> enable ;

    hope this help you .