【问题标题】:BrowserMob proxy and hosts fileBrowserMob 代理和主机文件
【发布时间】:2012-11-27 16:39:06
【问题描述】:

我正在尝试使用BrowserMob proxy 来监控 WebDriver(Selenium) 浏览器发送的请求。

我用以下方式实例化代理:

    server = new ProxyServer(localProxyPort);       
    server.start();

然后我创建将使用此代理的 Firefox 配置文件:

    FirefoxProfile profile = new FirefoxProfile(); 

    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "localhost");
    profile.setPreference("network.proxy.http_port", localProxyPort);      

我的问题是我的“主机”文件中有很多不同的主机映射。 BrowserMob 代理忽略系统主机文件,并尝试自行解析 ips。

有一个解决办法:

    server.remapHost("somehost.com", "127.0.0.1");

但我不能为每个主机都这样做。有没有办法强制代理使用我的系统主机映射?

谢谢!

莱昂蒂

【问题讨论】:

    标签: selenium proxy selenium-webdriver


    【解决方案1】:

    我们可以使用相同的函数重新映射多个主机:

    server.remapHost("somehost.com", "127.0.0.1");
    server.remapHost("someotherhost.com", IP Address);
    

    【讨论】:

    • 我知道,我所说的“我不能为每个主机都这样做”的意思是我有(有:))太多的映射,无法将它们中的每一个都放入 .remapHost()功能。
    • 您可以自动将 Hosts 文件转换为 remapHost 配置行。
    猜你喜欢
    • 1970-01-01
    • 2019-02-02
    • 2018-04-23
    • 1970-01-01
    • 2016-08-19
    • 2014-07-23
    • 2015-07-24
    • 2015-07-09
    • 1970-01-01
    相关资源
    最近更新 更多