1

I am getting this error when trying to connect to an API in flutter to get user data. The API is remote, the phone has connection to the internet, I'm using an android phone to build the APP.

this is the error. [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = address, port = 43798

for back end we are using PHP Laravel , but the API should be open to anyone who has the address at this point in development, so much so that the get request works both in Postman and in browser when calling.

As for the flutter function, this is the code being used.

   Future<User> getUser(url) async {
    print("here");
    var params = {
      "id": "01142",
    };

    Uri uri =
        Uri.parse(url);
    uri.replace(queryParameters: params);

    final response = await http.get(
      uri,
      headers: <String, String>{
        'Content-Type': 'application/json',
        'Accept': "*/*",
        'connection': 'keep-alive',
        'Accept-Encoding': 'gzip, deflate, br',
        'host': 'ipv4',
      },
    );

    if (response.statusCode == 200) {
      // If the server did return a 200 OK response,
      // then parse the JSON.

      user = User.fromJson(jsonDecode(response.body));
      print("NEW USER");
      print(user);
      return user;
    } else {
      // If the server did not return a 200 OK response,
      // then throw an exception.
      throw Exception('Failed to load user');
    }
  }

According to back end Laravel isnt using SSL either, what might be the problem?

Vitor Araújo
  • 292
  • 4
  • 19
  • Does this answer your question? [SocketException: OS Error: Connection refused, errno = 111 in flutter using django backend](https://stackoverflow.com/questions/55785581/socketexception-os-error-connection-refused-errno-111-in-flutter-using-djan) – RaSha Aug 20 '21 at 16:36
  • it unfortunately does not, the answer there requires a localhost, a thing that I am not using, I am using a remote host. I had checked that question before posting. – Vitor Araújo Aug 20 '21 at 17:47
  • refer my answer [here](https://stackoverflow.com/a/68546991/13997210) hope it help to you – Ravindra S. Patil Aug 20 '21 at 18:09
  • still same error, unfortunatelly – Vitor Araújo Aug 20 '21 at 18:20

0 Answers0