IeuanW
IeuanW

Reputation: 298

How to access localhost from on android emulator inside a VM?

I know the question sounds a bit confusing but here we go.

I am using an Azure VM to develop a cross platform app (Xamarin) and the app needs to utilise a .net core web API.

I am using a Google Emulator that has access to the internet.

What I have tried -

I have tried google emulators default connection 10.0.2.2:"MY WEB API PORT"/swagger. The result I get is "Bad request - invalid hostname"

I have tried a lot more but with no avail.

Any help is much appreciated.

Upvotes: 1

Views: 2310

Answers (1)

IeuanW
IeuanW

Reputation: 298

Ok, the problem was that when I ran the Web service on ISS Express from Visual Studio it wasn't running on my local IP address 127.0.0.1:[MY WEB API PORT].

I found this out thanks to @JasonYe-MSFT who told me about the command

netstat -ant

When I ran the command I found that the port that my web app was running on wasn't attached to my local IP instead it was formatted like so

[::]:64339

So in visual studio instead of running the web app using IIS Express, i changed it too the project itself and when i ran the command again, the port now had my local IP address connected to it.

Inside the android emulator, i can now load the web api using AVD default IP address '10.0.2.2'. So the full address is

10.0.2.2:"MY WEB API PORT"/swagger

Upvotes: 1

Related Questions