0

I'm using HttpClient in my Xamarin Forms project to call my Asp.net core REST Api with Base address: https://10.0.2.2:portNumber and everything works fine on the Emulator.

However when I test on my Android device it doesn't work and I don't even get any error. I tried changing the base address to my computer's IPv4 and disabling firewall like it was suggested in here How can I access my localhost from my Android device?. Still nothing seems to work.

I would really appreciate a help here. Thanks

  • IP of your computer should work. 10.0.2.2 is only for when running in emulator. Have you checked debug output? Must be saying something is wrong somewhere. If you try the IP from the browser on your device, does that work? – Cheesebaron Dec 06 '20 at 00:18
  • I don't get any output, It's as if it is taking very long time to load or an endless loop. Just nothing happens after i call the HttpClient.GetAsync(uri). On the browser I get: "This site can't be reached. 192.168.xxx.xx:44313/ refused to connect" The API is running on https://localhost:44313 – Hoka Turki Dec 06 '20 at 11:20
  • Most definitely networking issues. Nothing to do with android or xamarin. – Cheesebaron Dec 06 '20 at 12:21
  • maybe I am completely off but I have tried this https://github.com/icflorescu/iisexpress-proxy.. set my local address and then I used my phone and it worked.. Maybe completely different issue. Just a suggestion as I was facing similar issue – Vanessa Kensington Dec 06 '20 at 17:28
  • I will give it a try. Nothing else is working anyway.. Thanks – Hoka Turki Dec 06 '20 at 21:50
  • Could it work now ?Does the rest api require to use a specific port and if yes is that port open in the firewall of the server? – Leo Zhu Dec 08 '20 at 06:39
  • No, unfortunately it still doesn't work. Ye, it does use a specific port which is 44313. what do you mean with open in the firewall of the server or how can i open it if it's not? – Hoka Turki Dec 08 '20 at 13:58
  • Maybe you could look at [this](https://stackoverflow.com/questions/42365046/get-xamarin-android-device-calling-asp-net-web-api-running-localhost). – Leo Zhu Dec 09 '20 at 08:07

0 Answers0