首页 > 解决方案 > JavaFX webengine:为 https 网站使用 http 代理

问题描述

我正在尝试使用 javafx webengine/webview 连接到网站。我使用不支持 https 协议的代理(所以只有 http)。当我尝试连接到 http 网站时,它可以工作。但是,当我尝试加载 https 网站时,它会忽略代理并使用我的互联网连接。当我在浏览器中使用相同的代理时,我也能够连接到 https 网站,我想知道是否可以更改我的代码,以便网络引擎仍将使用我的 http 代理,而不是切换到我的正常互联网连接。

我的代码:

final String[] pArray = line.split(":");



            System.out.println("IP:" + pArray[0] + " Port:" + pArray[1]);
            System.setProperty("http.proxyHost",pArray[0]);
            System.setProperty("http.proxyPort",pArray[1]);
            System.setProperty("http.proxyUser",pArray[2]);
            System.setProperty("http.proxyPassword",pArray[3]);

            Authenticator.setDefault(
                      new Authenticator() {
                        @Override
                        public PasswordAuthentication getPasswordAuthentication() {
                          return new PasswordAuthentication(pArray[2], pArray[3].toCharArray());
                        }
                      }
                    );



            System.setProperty("java.net.useSystemProxies", "true");
            System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

当我加载我的网络引擎时:

engine.load("http://whatismyip.host");

该网站(仅限 http 的网站)显示代理 IP。

但是当我这样做时:

engine.load("https://myip.is");

它显示了我的家庭连接的 IP,这意味着它忽略了 http 代理......我该如何改变它?

问候

标签: javahttpjavafxproxywebengine

解决方案


推荐阅读