10

I am Using strapi.io open Source Node.js Headless CMS

this is my code for registerpage

void _registerUser() async {

http.Response response =
    await http.post('http://localhost:1337/auth/local/register', body: {
  "username": _userName,
  "email": _email,
  "password": _password,
});
final responseData = json.decode(response.body);

if (response.statusCode == 200) {
  // If the call to the server was successful, parse the JSON
  return print(responseData);
} else {
  // If that call was not successful, throw an error.
  throw Exception('Failed to load post');
}

}

any idea how to solve this

Problem about Socket exception

update:

Found the Solution: If you're running the server locally and using the Android emulator, then your server endpoint should be 10.0.2.2:8000 instead of localhost:8000 as AVD uses 10.0.2.2 as an alias to your host loopback interface (i.e) localhost

clear explanation checkout this Answer:

SocketException: OS Error: Connection refused, errno = 111 in flutter using django backend

Thank you So much Everyone For Helping me!!❤❤❤

Joundill
  • 6,828
  • 12
  • 36
  • 50
Sagar Shende
  • 221
  • 1
  • 2
  • 18

7 Answers7

16

1 open cmd

2 run ipconfig at cmd

3 copy IPv4 Address from cmd

4 at 'http://localhost:1337/auth/local/register' replace 'localhost' with your IPv4 Address

5 run your app

Mohamed Reda
  • 1,207
  • 13
  • 21
9

Instead of localhost, put your machine IP address. Mobile doesnt understand localhost.

Amit Sinha
  • 566
  • 7
  • 22
4

Worked for me!! Insert your local IP address (192.168.x.x) instead of localhost. You can find it by writing ipconfig on Windows CMD and by writing ifconfig on Linux Terminal.

3

For MAC Users

Instead of localhost, put your MAC IP address. Mobile will not understand localhost.

Click

apple logo > system prefrences > Network

Under connected networks you can find your wifi ip

after that instead of

http://localhost:1337

you can use your wifi ip

http://192.168.2.250

enter image description here

Anand
  • 4,355
  • 2
  • 35
  • 45
1

just check if you have given the internet permission and the you have good internet connection

Sagar Acharya
  • 3,397
  • 4
  • 12
  • 34
0

Use this library here for fetching data, And don't declare response as final and http.Response, instead of this you can use var

Tisha
  • 1
  • 3
0

I had de same issue, it was caused because I builded an app version with signed on debug mode, on Android Studio, it was ok. But later on when I tried to run on the app on visual studio the error appears!!, so I went to Android Studio in normal mode, and runned the app , the error desapears. Because these error only appeeared in Android versión.

Liliana J
  • 549
  • 1
  • 5
  • 13