In my flutter application, i have user registration form which sends the data to an server using http request.
Whenever I submit the form and sending the request using the emulator (API 27 and android version 8.1) which works fine but in real android device it gives a error on localhost server
SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 48134
I am working with Android device with version 7.1
Code:
final JsonDecoder _decoder = new JsonDecoder();
Future<dynamic> post() {
return http.post(
"http://192.168.31.16:9091/myprj/api/register",
body: json.encode({
"username": "rahul",
"password": "rahul",
"email": "myemail@gmail.com",
}),
headers: {"Accept": "application/json","Content-type": "application/json",},
).then((http.Response response) {
final String res = response.body;
final int statusCode = response.statusCode;
if (statusCode < 200 || statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
}
return _decoder.convert(res);
});
}
Where, i have used local network IP 192.168.31.16 instead of localhost.
When i use live server address it works fine using android device also. The problem is only with localhost http request server with real android device.
Hope you understand my problem.