How to use Flutter http request when the url contain port?

0

Issue

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?

Solution

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.

Answered By – Voicu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More