自从我开始编程java以来已经过了一个月。同时,我正在处理在经过身份验证的代理服务器上运行的java fx webview。我能够在运行此代码的http网站上连接:
Properties systemSettings = System.getProperties();
String User = "myusername";
String Password = "mypassword";
systemSettings.put("proxySet", "true");
systemSettings.put("https.proxyHost", "192.1.1.20");
systemSettings.put("https.proxyPort", "8888");
systemSettings.put("http.proxyHost", "192.1.1.20");
systemSettings.put("http.proxyPort", "8888");
Authenticator.setDefault(new ProxyAuthenticator(User ,Password));
HttpURLConnection conn = (HttpURLConnection) new URL("http://www.google.com/").openConnection();
String encodedUserPwd = Base64Converter.encode("myuser:mypassword".getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
conn.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
}
WebView webView = new WebView();
WebEngine engine = webView.getEngine();
engine.load("http://www.google.com/");
VBox root = new VBox();
root.getChildren().addAll(webView);
Scene scene = new Scene(root, 1200, 700);
primaryStage.setScene(scene);
primaryStage.show();
in.close();
但如果我将url更改为https,则会抛出java.net.UnknownHostException。需要帮助。