browsermob-proxy'服务器拒绝连接'错误

时间:2014-08-14 12:25:08

标签: browsermob

Selenium Webdriver 2.42.2,browsermob-proxy Beta 9,Windows 7 / Firefox

我正在尝试调用browsermob-proxy API来捕获http网络请求,并在执行example之后。但是,我收到以下错误:

The proxy server is refusing connections

Firefox配置为使用拒绝连接的代理服务器。

Check the proxy settings to make sure that they are correct.
Contact your network administrator to make sure the proxy server is working.

任何人都知道这可能是网络问题,我们在网络中不使用代理服务器。我还运行了browsermob-proxy.bat -port 9090来启动服务器。以下是我尝试过的代码示例:

public void setDriver(String browser,String environment,String platform) throws Exception {
ProxyServer server = null;

// start the proxy
server = new ProxyServer(9091);
server.start();
server.setCaptureHeaders(true);
server.setCaptureContent(true);

// set the Selenium proxy object
Proxy proxy = server.seleniumProxy();
//Proxy proxy = new Proxy();
//proxy.setHttpProxy("localhost:9091");

caps = DesiredCapabilities.firefox();
caps.setCapability(CapabilityType.PROXY,proxy);

server.newHar("test");

public void closeDriver() throws Exception {
Har har = server.getHar(); // browserMob proxy

FileOutputStream fos = new FileOutputStream("C:/Downloads/browserMob.har");
har.writeTo(fos); // browserMob proxy
server.cleanup(); // browserMob proxy
server.stop(); // browserMob proxy

this.driver.quit();

2 个答案:

答案 0 :(得分:1)

有两种变体: 1)Browsermob Proxy Server没有启动; 2)Proxy Server以错误的参数启动;

如果您遇到第二个问题,请尝试以下代码:

                server = new ProxyServer(9091);     
                server.setLocalHost(InetAddress.getByName("localhost"));
                server.start();
                server.setCaptureContent(true);
                server.setCaptureHeaders(true);

答案 1 :(得分:0)

如上所述,但有几点想法:

  1. 尝试使用Firefox个人资料:
    如下所述:Webdriver and proxy server for firefox

  2. 尝试通过以下方式添加地址参数:InetAddress.getLocalHost()

  3. 确保端口已打开。