问题
I have tried loading a WebView with a SSL page, and I am getting an error. Code and error below. I have set my permissions to allow Internet access.
I think this is a Mono-only issue. When I try my SSL web page in the default browser it works fine.
WebView webView = new WebView(this);
string website = "https://...";
webView.Settings.JavaScriptEnabled = true;
webView.SetWebViewClient(new WebViewClientAuthentication());
webView.LoadUrl(website);
//definition for WebViewClientAuthentication
public class WebViewClientAuthentication : WebViewClient
{
public override void OnReceivedSslError(WebView view, SslErrorHandler handler, Android.Net.Http.SslError error)
{
Log.Error("SSL ERROR",string.Format("SSL ERROR: {0}, Primary: {1}", error.GetType.ToString(), error.PrimaryError.ToString()));
base.OnReceivedSslError(view, handler, error);
}
}
OUTPUT SSL ERROR: Android.Net.Http.SslError, Primary: Notyetvalid
COMMENTS I have seen this message: http://mono-for-android.1047100.n5.nabble.com/SSL-issues-td5629485.html - but I am not sure what it means in terms of loading SSL sites into a webview.
回答1:
Try this:
//definition for WebViewClientAuthentication
public class WebViewClientAuthentication : WebViewClient
{
public override void OnReceivedSslError(WebView view, SslErrorHandler handler, Android.Net.Http.SslError error)
{
handler.Proceed();
}
}
来源:https://stackoverflow.com/questions/12034452/monodroid-webview-loading-ssl-page