Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)


To handle basic, digest or NTLM authentication you can use the NetworkDelegate.onAuthRequired(AuthRequiredParams params) handler. (要处理基本身份验证,摘要身份验证或NTLM身份验证,可以使用NetworkDelegate.onAuthRequired(AuthRequiredParams params)处理程序。)


To display authentication dialog where user can enter valid user name and password you must register default Swing/JavaFX implementation of the NetworkDelegate or your own implementation of the NetworkDelegate interface.(要显示身份验证对话框,用户可以在其中输入有效的用户名和密码,您必须注册NetworkDelegate的默认Swing / JavaFX实现或您自己的NetworkDelegate接口的实现。)


The following example demonstrates how to register and override default Swing implementation of the NetworkDelegate interface in order to provide user name and password without displaying authorization dialog:(下面的示例演示如何注册和覆盖NetworkDelegate接口的默认Swing实现,以便在不显示授权对话框的情况下提供用户名和密码:)

browser.getContext().getNetworkService().setNetworkDelegate(new DefaultNetworkDelegate() {
    @Override
    public boolean onAuthRequired(AuthRequiredParams params) {
        if (!params.isProxy()) {
            params.setUsername("proxy-username");
            params.setPassword("proxy-password");
            // Don't cancel authentication
            return false;
        }
        // Cancel authentication
        return true;
    }
});