WebView加载https的空白及图片加载不了的问题
Posted 大白龙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WebView加载https的空白及图片加载不了的问题相关的知识,希望对你有一定的参考价值。
目前ios现在都需要换成https请求,现在遇到一个webview加载https的有一些问题及解决办法。
1、webview加载https空白页面
解决办法:
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
handler.proceed(); // Ignore SSL certificate errors
或者可以这么写:
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error)
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
String message = "SSL Certificate error.";
switch (error.getPrimaryError())
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted.";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired.";
break;
case SslError.SSL_IDMISMATCH:
message = "The certificate Hostname mismatch.";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid.";
break;
message += " Do you want to continue anyway?";
builder.setTitle("SSL Certificate Error");
builder.setMessage(message);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
handler.proceed();
);
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener()
@Override
public void onClick(DialogInterface dialog, int which)
handler.cancel();
);
final AlertDialog dialog = builder.create();
dialog.show();
解决办法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
以上是关于WebView加载https的空白及图片加载不了的问题的主要内容,如果未能解决你的问题,请参考以下文章
webview_flutter3.0.4无法加载http图片