How to connect to a REST web service on a local host using a phone as emulator?

I try to run the example "TodoREST". Because my processor doesn't support SLAT I cannot use an (Android) emulator so I use my phone in stead. When I run the projects the TodoApi output appears in the browser and the app runs on my phone. There is a call to the Task list but it returns an error saying that there is a connection timeout. When using an emulator I have to use 1.0.2.2:5001 to call the localhost. But I use a phone. Maybe this is different?

Answers

  • matrixlukanmatrixlukan Member ✭✭

    Step 1 :
    If your api is a c# project then you can bind your Urls to http://0.0.0.0:YOUR_PORT.
    Change your Program.cs file to add Urls.

    return WebHost.CreateDefaultBuilder(args)
                    .UseUrls("http://0.0.0.0:_YOUR_PORT_")
                    .UseStartup<Startup>();
    

    Step 2 :
    Connect your android device to your servers network (recommended to connect via wifi).

    Step 3 :
    Find the IP address of the server by running the command ipconfig in command prompt.

    Step 4 :
    Replace http://10.0.0.2 with server's IP address in xamarin project.

Sign In or Register to comment.