1

I'm building flutter project to access localhost machine using http, the problem android emulator cant access host-name. I want to get url working for api that provide json.

Edit file system32/drive/etc/hosts

127.0.0.1 localhost
127.0.0.1 hipiapp.test

192.xxx.xx.xx localhost
192.xxx.xx.xx hipiapp.test

Error if connect without ipaddress(this link work if use normal web browser but not in android studio)

final String urlApi = 'http://hipiapp.test/api/index';
'hipiapp.test' (OS Error: No address associated with hostname, errno = 7)

if I use full with my ip , error url not found.

final String urlApi = 'http://192.xxx.xx.xx/hipiapp.test/api/index';
azra abdullah
  • 139
  • 1
  • 5
  • 12
  • 1
    You are aware that the emulator has its own `localhost`? https://stackoverflow.com/questions/49855754/unable-to-make-calls-to-localhost-using-flutter-random-port-being-assigned-to-h/49855877#49855877 might help you. – Günter Zöchbauer Apr 18 '18 at 07:06
  • Does your server app on `192.xxx.xx.xx` listen to the public interface or only to 127.0.0.1`? – Günter Zöchbauer Apr 18 '18 at 07:06
  • Only 192.xxx.xx.xx. change to adb reverse --list host-12 tcp:5000 tcp:5000 still cant use http://hipiapp.test/api/index – azra abdullah Apr 18 '18 at 07:39
  • Your emulator would need to find a DNS that resolves `http://hipiapp.test/api/index`, but because it's not a registered domain it can't resolve it. You should be able to connect to a server listening on your development machine on port 5000 using `http://localhost:5000` – Günter Zöchbauer Apr 18 '18 at 07:45
  • https://developer.android.com/studio/run/emulator-networking.html has some more suggestions – Günter Zöchbauer Apr 18 '18 at 07:46
  • 1
    SOLVED, Sorry,not mention you earlier that api was requested from my local laravel 5.6 development. Solve the issue run php artisan serve --host 0.0.0.0 and use http://192.xxx.xx.xx:8000/api/index Thank you for your assisting. – azra abdullah Apr 18 '18 at 08:59

1 Answers1

0

As mentioned in the comments, it looks like the issue was caused by a conflicting network address where another host is serve. To solve this issue, you can either change the network address where the emulator is running or change the address of the conflicting deployment.

Omatt
  • 8,564
  • 2
  • 42
  • 144