HtmlUnit's proxy configuration selects the intermediary, and its credential provider supplies the account for that host and port. For an NTLM proxy, the HtmlUnit 4.21.0 API has a dedicated method:

String proxyHost = "proxy.example";
int proxyPort = 8080;
DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
credentials.addNTLMCredentials(
    user, password.toCharArray(), proxyHost, proxyPort, workstation, domain);

try (WebClient browser = new WebClient()) {
    browser.getOptions().setProxyConfig(
        new ProxyConfig(proxyHost, proxyPort, "http"));
    browser.setCredentialsProvider(credentials);
    HtmlPage page = browser.getPage("https://www.example.com/");
}

The classes use the current org.htmlunit packages, with HtmlPage in org.htmlunit.html. Supply the proxy account's workstation and domain according to the environment; the destination website is not the NTLM domain field.

For a generic username/password credential entry, the same provider offers addCredentials with username, char-array password, host, port and realm. A null realm applies to any realm on that scoped endpoint.

Use the overload matching the proxy's authentication scheme and the dependency actually deployed. Old HtmlUnit 2.x examples use different package names and may have string-password signatures; the code above uses the 4.21.0 API.

Allakkat attuumassuteqartut