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?