如何使用HtmlUnit驱动程序对代理进行身份验证?

时间:2019-06-21 21:34:13

标签: java selenium htmlunit-driver

我正在使用Selenium来抓取网站,并希望通过代理发送我的请求。如何使用HtmlUnit驱动程序验证对代理服务器的请求?

使用Chrome驱动程序时,我已经成功验证了请求,因此问题不在于用户名和密码组合不正确,或者IP不可用。

/// <summary>
/// Draw logic. Activates every frame.
/// </summary>
/// <param name="gameTime">How long the program has been running for</param>
protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.Chocolate);

    foreach (var a in blocks)
        a.Draw();

     fps++;

     if (gameTime.TotalGameTime.Milliseconds % 1000 == 0 && enableFpsCounter)
     {
         Console.WriteLine(fps);

         fps = 0;
     }

     base.Draw(gameTime);
}

此代码段显示公共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(); 的值,但是请求不会通过代理传递并读取我的家庭IP地址。

0 个答案:

没有答案