我仅对Android jelly bean(4.1, 4.2, 4.3)
使用以下代码
我覆盖了shouldInterceptRequest()
webViewclient
public WebResourceResponse shouldInterceptRequest(WebView view, String sourceurl) {
try {
URL url = new URL(sourceurl);
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
//make https connection using tls
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
SSLSocketFactory noSSLv3Factory = null;
noSSLv3Factory = new TLSSocketFactory();
urlConnection.setSSLSocketFactory(noSSLv3Factory);
String responseEncoding = urlConnection.getContentEncoding();
String responseMimeType = urlConnection.getContentType();
return new WebResourceResponse(responseMimeType, responseEncoding, urlConnection.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我使用TLSSocketFactory类为HttpsURLConnection请求创建了启用TLS的套接字。它工作正常。
现在webview显示我的网站,但它没有加载网站中的任何js文件。我的网页中没有发生这么多事件。然后,当我运行我的应用程序时,它会出现以下错误:
E/Web Console: Uncaught SyntaxError: Unexpected token ILLEGAL at https://www.google-analytics.com/analytics.js:1
E/Web Console: Uncaught SyntaxError: Unexpected token ILLEGAL at https://mytestsite.com/wp-includes/js/jquery/jquery.js?ver=1.12.4:1
所有java脚本文件都没有加载相同的错误消息。