2017-08-18 142 views
0

我能夠使用BrowserMob創建Selenium代理,在我的本地PC上一切正常。當我在服務器上運行相同的代碼時(Windows Server 2008 R2標準版),它會出錯我們的「無法連接到隧道」。通過BrowserMob設置時無法訪問Selenium代理

我嘗試過不同的Chrome開關組合,例如--ignore-certificate-errors, - user-data-dir = C:/ temp/insecurechrome, - ignore-certificate-errors。我已確保.setTrustAllServer(true)已設置。我曾嘗試調整Windows Firewal而沒有任何影響。

我將添加我使用的代碼,但是,它在我的本地PC上工作,但不在服務器上。我希望有人可以建議服務器上的其他設置,我可以改變或我可能錯過了我的代碼中的東西。

我首先得到一個Chrome瀏覽器消息:代理隧道。幾秒鐘後(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); 
+0

與普通PC相比,Windows Server版本有更嚴格的限制。您可能面臨與防火牆相關的問題或阻塞的端口。檢查那些在Windows服務器。首先手動設置安裝程序,然後檢查自動化版本 –

+0

作爲檢查,我已成功在Windows 2008 Server上運行BrowserMob代理(手動)。訪問我需要花費更長時間來檢查Internet選項中的防火牆和公司代理設置。感謝您的建議。 –

+0

您是否認爲在BrowserMob中設置和使用證書會解決此問題?這是我可能接下來嘗試的事情。 –

回答

0

我能弄清楚我自己的問題。有一個現有的公司代理正在攔截流量。這個代理服務器和用戶有不同的協議。在我的電腦上運行時,運行良好。在服務器上運行我的程序時,我需要解決代理轉發或鏈接問題。我通過將下面的代碼添加到我的上面的代碼中來實現此目的:

import java.net.InetSocketAddress; ... ...

InetSocketAddress x = new InetSocketAddress(「proxy.example.com」,80); browserMobProxyServer.setChainedProxy(x);

相關問題