** update ** Fixed it by editing my server to listen on 0.0.0.0 Getting a response now, but still, the error message wasn't right, it should've shown port 3333 not a random port. --- // ---
While trying to make a post request to http://192.168.1.1:3333, I get this error:
SocketException (SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.2.9, port = 53744)
The port changes on every request but is never the right port (3333) why is that? This is my code
class Api {
static const req_url = 'http://192.168.1.1:3333/api/auth/login';
Future<Auth> fetchAuthToken() async {
Map data = {
'email': 'test@gmail.com',
'password': '123456'
};
//encode Map to JSON
var body = json.encode(data);
var response = await http.post(req_url,
headers: {"Content-Type": "application/json"},
body: body
);
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return Auth.fromJson(json.decode(response.body));
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
}
I've tried changing the ip to 10.0.2.2 as mentioned here but I'm not using an emulator so not sure if that even matters.