4

Problem is urls with Self Signed SSL Certificates are being rejected by the WebView on Android resulting in a white screen.

I understand this question has been answered. These solutions do not work. You can see by the comments it does not work for many others. ServicePointManager will work for IOS and compile for Android but the callback will never be raised on Android resulting in the white WebView.

In Xamarin.Forms I have my full page WebView.

    <WebView x:Name="Browser" HeightRequest="1000" WidthRequest="1000"/>

In my Android project MainActivity.cs I have tried the suggested ServicePointManager which does not work. Instead in my OnCreate of MainActivity.cs I problematically add a AddInvalidWebClient.

    private void AddInvalidWebClient()
    {
        WebView wb = new WebView(this);
        wb.SetWebViewClient(new InvalidWebViewClient());
        wb.LoadUrl("https://invalidcertificate.com");
        // Not required for Invalid certificate, but required for my site.
        WebSettings ws = wb.Settings;
        ws.JavaScriptEnabled = true;
        // Add our new wb.
        SetContentView(wb);
    }

My InvalidWebViewCient is very basic. It inherits standard WebViewClient and suppresses the SSL error.

    public class InvalidWebViewClient : WebViewClient
    {
        public override void OnReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
        {
            handler.Proceed();
        }
    }

Is there another/better way to ignore SSL Erros on Xamarin.Forms WebView for Android? ServicePointManager does not work and adding another WebView in my MainActivity.cs seems counter active (not to mention hacky) for Xamarin.Forms.

P.S. I understand it's bad to suppress all SSL errors. Once I'm confident I have a solution I will build in a way to suppress them only for my certificates public key.

clamchoda
  • 4,411
  • 2
  • 36
  • 74
  • Implement your own ViewRenderer for WebView (like in the Xamarin's HybridWebView example) that contains a subclassed WebView that implements a subclassed WebViewClient that overrides OnReceivedSslError. – SushiHangover Apr 30 '19 at 19:41
  • Use can see this link for reference https://gist.github.com/MansiShah04/2638427748d11f69aee85d22010e1f91 – Adit Kothari May 01 '19 at 04:55

0 Answers0