我正在开发 JavaFX 应用程序,并尝试使用 WebView 访问 Web 应用程序。该 Web 应用程序具有基本身份验证,我想以编程方式提交凭据(不想提示用户输入凭据,它们存储在 JavaFX 应用程序中,我知道这种方法的安全隐患)。
我在谷歌中找到的唯一链接是:
https://community.oracle.com/message/12518017
目前还没有答案。
最佳答案
我们实际上正在尝试使用Authenticator
的方法并且它有效。
URI baseUri = URI.create("https://my.company.com/");
String username = "";
String password = "";
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
// only return our credentials for our URI
if (baseUri.getHost().equals(getRequestingHost())) {
return new PasswordAuthentication(username, password.toCharArray());
}
return null;
}
});
关于javafx - 如何以编程方式在 WebView 中使用基本身份验证 - JavaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33879165/