简体   繁体   中英

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

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://docs.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:

在此处输入图像描述

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:-)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM