0

I'm using Selenium in order to scrape a website, and want to send my requests through a proxy. How do I authenticate requests to the proxy server using HtmlUnit driver?

I've successfully authenticated requests when using the Chrome driver, so the problem doesn't lie with an incorrect username and password combo nor an unavailable ip.

final HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true) {
    @Override
    protected WebClient modifyWebClient(WebClient client) {
        final DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
        credentialsProvider.addCredentials(USERNAME, PASSWORD, HOST, PORT, AuthScope.ANY_REALM);
        client.setCredentialsProvider(credentialsProvider);
        return client;
    }
};

driver.get("http://ipinfo.io/ip");

System.out.println(driver.findElement(By.tagName("body")).getText());

driver.quit();

This code snippet displays the public ip address. I expect the value printed to read the value of HOST, but instead the request doesn't pass through the proxy and reads my home ip address.

veyndan
  • 382
  • 5
  • 9

0 Answers0