自定义shouldInterceptRequest()不在android的webview上加载javascript(jelly bean)
我只对Android果冻豆(4.1、4.2、4.3)使用以下代码 我在自定义shouldInterceptRequest()不在android的webview上加载javascript(jelly bean),java,android,webview,webviewclient,Java,Android,Webview,Webviewclient,我只对Android果冻豆(4.1、4.2、4.3)使用以下代码 我在webViewclient public WebResourceResponse shouldInterceptRequest(WebView view, String sourceurl) { try { URL url = new URL(sourceurl); HttpsURLConnection urlConnection = (HttpsURLConnection)
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;
}
我使用类创建启用TLS的套接字到HttpsURLConnection请求。它很好用
现在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脚本文件都加载了相同的错误消息。您是否能够解决问题?