import org.htmlunit.ProxyConfig;
import org.htmlunit.WebClient;

try (WebClient browser = new WebClient()) {
    ProxyConfig proxy =
        new ProxyConfig("proxy.example.net", 8080, "http");
    proxy.addHostsToProxyBypass("localhost");
    browser.getOptions().setProxyConfig(proxy);

    browser.getPage("https://example.net/");
}

Set ProxyConfig on the WebClient that loads the page before navigation. This uses the org.htmlunit namespace; older dependencies used com.gargoylesoftware.htmlunit and may expose different constructors.

Replace the proxy host and integer port with an unauthenticated candidate from the HTTP proxy list for this public-page example. The constructor's "http" describes the intermediary, even for an HTTPS page. Do not put a URL prefix into the hostname argument or change protocol just to match the destination.

Bypass values are regular expressions, not PAC rules or a comma-separated environment list. For a request unexpectedly going direct, compare the requested host with those patterns and confirm it uses this WebClient.

A separately created WebClient or HTTP client does not inherit this configuration object. Configure reusable instances before their work instead of changing global state around concurrent requests. Destination verification and website login remain separate; an authenticated proxy also needs the credentials interface of the installed HtmlUnit version. For example, HtmlUnit 4.21.0 scopes proxy credentials by host and port.

འབྲེལ་བའི་རྩོམ་ཡིག