JavaFX WebView 无法加载某些站点 [英] JavaFX WebView can't load certain sites
问题描述
我正在尝试使用 JavaFX 的 WebView 加载此站点,但我得到的只是空白屏幕.WebView 在其他站点上运行良好;它在 ACID3 上获得 100/100 并加载其他 HTTPS 站点而没有任何问题.
I'm trying to use JavaFX's WebView to load this site, but all I get is a blank screen. The WebView is working perfectly fine on other sites; it gets 100/100 on ACID3 and loads other HTTPS sites without any problems whatsoever.
我也找不到该网站的任何特别错误.它有一个由适当的 CA 签署的适当的、未过期的证书,并且 SSL 实验室报告 B 级.我尝试了所有主流浏览器,但没有报告任何证书或 SSL 相关问题;该网站在所有这些方面都表现良好.
I can't find anything particularly wrong with the site either. It has a proper, non-expired certificate signed by proper CA, and SSL Labs report a B grade. I tried all the major browsers on it and none report any certificate or SSL related issues; the site renders fine on all of them.
任何帮助将不胜感激.即使是简单的是的,该网站对我来说也坏了"或这里没有问题"也会有很大帮助.
Any help would be greatly appreciated. Even a simple "yeah the site's broken for me too" or "no problems here" would help a lot.
我在 Windows 8.1 64 位上使用 Java SDK 1.8.0_45-b14.
I'm using Java SDK 1.8.0_45-b14 on Windows 8.1 64-bit.
推荐答案
原因是java.lang.Throwable: SSL握手失败
一种解决方案可以是:从这篇文章https://stackoverflow.com/a/5671038/1032167:
One solution can be: from this post https://stackoverflow.com/a/5671038/1032167:
TrustManager trm = new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {return null;}
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trm }, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
也有帖子,大概是类似的情况:JavaFx Webview JDK 8 无法加载自签名证书
There is also post, probably about similar case: JavaFx Webview JDK 8 can not load self signed certificate
我怎么知道是SSL握手失败
webView.getEngine().getLoadWorker().stateProperty().addListener(
new ChangeListener<Worker.State>() {
public void changed(ObservableValue ov,
Worker.State oldState, Worker.State newState) {
System.out.println(webView.getEngine().getLoadWorker().exceptionProperty());
...
同时添加 add -Djavax.net.debug=all
到 VMOption 显示
also adding add -Djavax.net.debug=all
to VMOption shows
URL-Loader-1,处理异常:javax.net.ssl.SSLHandshakeException:
URL-Loader-1, handling exception: javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException:PKIX 路径构建失败:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
sun.security.provider.certpath.SunCertPathBuilderException:
无法找到到请求目标的有效认证路径
unable to find valid certification path to requested target
这篇关于JavaFX WebView 无法加载某些站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!