1

I am trying to send post request to a website with port configured. http://example.com:8080/. When i send the request, it show some error

http.post('example.com:8080/apps/api.php', body: {'name': 'doodle', 'color': 'blue'}).then((response) {
  print(response);
});

Unhandled Exception: SocketException: Failed host lookup: 'example.com' (OS Error: No address associated with hostname, errno = 7)

The port is ignored there. Is there any way i can do to fix this? Or is there any other http library that i can use?

dango sjv
  • 163
  • 1
  • 3
  • 10

2 Answers2

0

This is probably not a port issue. Make sure you set the correct permissions in the Android manifest file (android/app/src/main/AndroidManifest.xml) to be able to make HTTP calls from your Android app:

<uses-permission android:name="android.permission.INTERNET" />

More details on that here and the official documentation from Android on permissions here.

Voicu
  • 16,921
  • 10
  • 60
  • 69
0

If you have added this line <uses-permission android:name="android.permission.INTERNET" /> at android/app/src/main/AndroidManifest.xml then try restarting emulator or computer itself. In my case, I restarted my laptop and it was fine. Most of the times restarting computer will solve the problems like this.

atigdawgahb
  • 41
  • 1
  • 5