Xamarin.Forms Android : access localhost (10.0.2.2) from WebView

2.3k views Asked by At

I have a Xamarin.Forms mobile app, this one contains a WebView. This WebView URL should be my local development machine because I have a web app running there.

So, when running the Android Emulator, I try to use the loopback address, https://10.0.2.2:44390 ... but the WebView remain white!

I have read the following docs, but it does not help:

https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services

https://medium.com/@noumaan/ssl-app-dev-a2923d5113c6

https://developer.android.com/studio/run/emulator-networking

This doc seems to focus on accessing a WebAPI, with a HttpClient, but I'm not sure that this scenario is correct for the WebView.

Noticed that from 'Chrome android', I got the following message: 'HTTP Error 400. The request hostname is invalid'. I got the following dialog:

enter image description here

Does my Blazor app (using a self-signed certificate) should use '10.0.2.2' instead of 'localhost' by example ?

If someone has any idea, really welcome :-)

1

There are 1 answers

0
Jaap Mosselman On

In your applicationhost.config change in the bindingInformation the 'localhost' to '127.0.0.1'. That solved it for me. See this answer where I found the solution.