通过 BrowserMob 进行设置时无法访问 Selenium 代理



我能够使用BrowserMob创建一个Selenium代理,在我的本地PC上一切正常。 当我在服务器(Windows Server 2008 R2 Standard(上运行相同的代码时,它错误我们的"无法连接到隧道"。

我尝试了Chrome swithes的不同组合,例如--ignore-certificate-errors,--user-data-dir=C:/temp/insecurechrome,--ignore-certificate-errors。 我已经确保设置了.setTrustAllServer(true(。 我尝试调整Windows Firewal没有任何效果。

我将添加我正在使用的代码,但是,它确实适用于我的本地 PC,但不适用于服务器。 我希望有人可以在服务器上建议我可以更改的其他设置或我可能错过的代码中的某些内容。

我首先收到一条 Chrome 浏览器消息:wing for Proxy Tunnel。 几秒钟后(15-20(。 我收到错误:ERR_TUNNEL_CONNECTION_FAILED。

browserMobProxyServer = new BrowserMobProxyServer(); 
browserMobProxyServer.setTrustAllServers(true);
browserMobProxyServer.start(0);
port = browserMobProxyServer.getPort();
seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxyServer);
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server","--ignore-certificate-errors","--user-data-dir=C:/temp/insecurechrome");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
PropertyConfigurator.configure("./resources/properties/log4j.properties");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
//desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);  //Has no effect
driverService = new ChromeDriverService.Builder().usingDriverExecutable(new File("./resources/driver/chromedriver.exe")).usingPort(Integer.parseInt(portRequested)).build();
driverService.start();
return new ChromeDriver((ChromeDriverService)driverService, desiredCapabilities);   

我能够弄清楚我自己的问题。 有一个现有的公司代理正在拦截流量。 此代理对服务器和用户具有不同的协议。 在我的PC上运行时,它运行良好。 在服务器上运行我的程序时,我需要解决代理转发或链接问题。 我通过将以下行添加到上面的代码中来实现这一点:

导入java.net.InetSocketAddress; ... ...

InetSocketAddress x = new InetSocketAddress("proxy.example.com", 80(; browserMobProxyServer.setChainedProxy(x(;

最新更新