简体   繁体   English

WebViewClient :: onReceivedSslError不被调用

[英]WebViewClient::onReceivedSslError is not called

I have attached my WebViewClient implementation to my WebView. 我已将我的WebViewClient实现附加到我的WebView。

appView.setWebViewClient(new AppViewClient());

My onReceivedSslError and onReceivedError implementations are called with all expected errors except for Mixed Content error. 调用了我的onReceivedSslErroronReceivedError实现,并带有除Mixed Content错误之外的所有预期错误。

My implementation for both methods: 我对两种方法的实现:

Log.i(TAG, "Error Cought");

As I said, they are called on various errors except the Mixed Content error. 就像我说的那样,除了Mixed Content错误外,它们还会因各种错误而被调用。 My request is blocked without calling either of these methods. 我的请求被阻止,而没有调用这些方法之一。

Which API version are you using? 您使用的是哪个API版本? MIX CONTENT was allowed, by default, before 21. 默认情况下, MIX CONTENT允许在21之前。

You can try adding this setting in web view: 您可以尝试在网络视图中添加此设置:

webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);

For API level below 21 : 对于低于21的API级别:

try {
    Method m = WebSettings.class.getMethod("setMixedContentMode", int.class);
    if ( m != null ) {

     m.invoke(webView.getSettings(), 1); //MIXED_CONTENT_NEVER_ALLOW

    }
}
catch (Exception ex) {

}

Good to know that you already know about MixedContentMode :) I can suggest 2 things to try. 很高兴知道您已经了解MixedContentMode :)我可以建议您尝试2件事情。

  1. Use console message to identify this error. 使用控制台消息来识别此错误。 You can do a string match to check the MIX CONTENT error. 您可以进行字符串匹配以检查MIX CONTENT错误。
myWebView.setWebChromeClient(new WebChromeClient() {
  public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    Log.d("MyApplication", message + " -- From line "
                         + lineNumber + " of "
                         + sourceID);
  }
});
  1. Intercept request and check the url. 拦截请求并检查网址。 Check the WebActivity implementation in source code . 检查源代码中的WebActivity实现。

     mWebView.setWebViewClient(new WebViewClient() { @Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { String url = request.getUrl().toString(); if (!URLUtil.isHttpsUrl(url)) { Logger.loge("Secure connection required, but insecure URL requested " + "explicitly, or as a part of the page."); return createNewSecurityErrorResponse(); } return super.shouldInterceptRequest(view, request); } }); private WebResourceResponse createNewSecurityErrorResponse() { WebResourceResponse response = new WebResourceResponse("text/plain", "UTF-8", null); response.setStatusCodeAndReasonPhrase(HTTP_FORBIDDEN, "Secure connection required"); return response; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Play警告:WebViewClient.onReceivedSslError处理程序 - Google Play Warning: WebViewClient.onReceivedSslError handler Android不安全的WebViewClient.onReceivedSslError处理程序实现 - Android unsafe implementation of WebViewClient.onReceivedSslError handler WebViewClient onPageFinished从未调用 - WebViewClient onPageFinished never called WebViewClient第二次未调用 - WebViewClient not called the second time 如何在没有WebViewClient.onReceivedSslError的情况下将我的应用成功上传到Play商店 - How to successfully upload my app to the play store without WebViewClient.onReceivedSslError 如果证书是从特定的自签名CA签名的,请检查WebViewClient的onReceivedSslError()方法 - Check in the onReceivedSslError() method of a WebViewClient if a certificate is signed from a specific self-signed CA WebViewClient loadData onPageFinished 没有被调用 - WebViewClient loadData onPageFinished not getting called 永远不会调用WebViewClient中的onPageFinished / onPageStarted - onPageFinished/onPageStarted in WebViewClient is never called android 2.2中的WebViewClient不应该调用OverlyUrlLoading - WebViewClient in android 2.2 shouldOverrideUrlLoading not called Android-具有多个webViewClient的多个webView:在新的webViewClient上未调用shouldOverrideUrlLoading - Android - multiple webViews with multiple webViewClient : shouldOverrideUrlLoading not called on new webViewClient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM