[英]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. 调用了我的onReceivedSslError
和onReceivedError
实现,并带有除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件事情。
myWebView.setWebChromeClient(new WebChromeClient() {
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
}
});
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.