JavaFX webview设置代理 [英] JavaFX webview set Proxy

查看:205
本文介绍了JavaFX webview设置代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用JavaFX webview。在其中我加载了一个本地html文件,该文件本身从maps.google.com加载一些javascript库,然后在webview中显示带有一些标记的谷歌地图。

I'm using a JavaFX webview in my application. Inside of it I load a local html file, which itself loads some javascript library from maps.google.com and then displays a google map with some markers inside the webview.

现在根据这个问题,如果我想使用代理,我应该这样做:

Now according to this question if I want to use a proxy I should just do:

System.setProperty("http.proxyHost","proxy.esrf.fr");
System.setProperty("http.proxyPort","3128");

但这没有效果。我可以设置我想要的任何东西作为主机和端口。即使设置不是有效代理,Google地图图块仍会加载。显然它没有使用代理设置。

But this has no effect. I can set whatever I want as the host and port. The google map tiles are still loaded, even if the settings are no valid proxy. So apparently it is not making use of the proxy settings.

我如何确保WebView中的所有Web流量都通过代理进行。

How can I make sure, that all web traffic within the WebView is going via the proxy.

我还设置了https.proxyHost和https.proxyPort,以防万一。

I also set the https.proxyHost and https.proxyPort by the way, just in case.

谢谢!

推荐答案

问题是由错误修正我造成的早些时候做过
在java中使用代理时这篇文章非常有帮助。最后,它建议设置
ProxySelector.setDefault(null);
以避免套接字和代理问题。

The problem was cause by a bugfix I did earlier. When working with proxies in java this post is quite helpful. In the end it recommends setting ProxySelector.setDefault(null); to avoid issue with sockets and proxies.

然而,这通过

System.setProperty("http.proxyHost","proxy.esrf.fr");
System.setProperty("http.proxyPort","3128");

不可能。实际上,除了将Proxy对象传递给 URL.openConnection(Proxy p);

impossible. Actually, it wasn't possible to set any proxy at all except by passing a Proxy object to URL.openConnection(Proxy p);

因此,我建议设置

ProxySelector.setDefault(ProxySelector.getDefault());

这篇关于JavaFX webview设置代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆