Unable to call API running on localhost from ionic android app running on emulator

Hello all,
I am new to ionic and trying to build a simple app which should hit the asp.net core api running on localhost and get some data.
I tried following pieces of codes, but none seems working from emulator. (PS: code works fine with browser)


Can someone please suggest me how to solve it ?

Thanks in advance !!!

Can u access the endpoint from a browser IN the emulator? If not, then your networking bridge van emulator to local network is not ok

Nope. But just to ensure I’m doing it correctly, what url do we enter in the browser ??


Well the same one as you use in the http-get. And if that does not work, you problem may be indeed be in the routing.

After all, how can you expect your app to reach something outside the emulator if a proven browser won’t be able to reach the same?

I would suggest never using either localhost or numeric IP addresses for anything. They cause more trouble than they’re worth, and they retard your ability to use HTTPS, kicking an entire new phylum of bugs down the road for a while. Use actual DNS hostnames - the .invalid top-level domain is explicitly reserved for this sort of activity.

Could you please explain this in little more details please ?