Unable to local page with error & ERR_EMPTY_RESPONSEERR_PROXY_CONNECTION_FAILED

22 views
Skip to first unread message

linda xu

unread,
Mar 18, 2021, 5:02:01 AM3/18/21
to BrowserMob Proxy
code as below. Chrome in use is Version 88.0.4324.182 (Official Build) (64-bit)
The browser can be open but the site e.g https://www.baidu.com/ cannot loaded .
Could u please help for this issues ?  Thanks a lot! 

public void testProxy() throws IOException, InterruptedException
  {
  CertificateAndKeySource rootCertificateGenerator = RootCertificateGenerator.builder()
            .keyGenerator(new ECKeyGenerator())
            .build();

    // tell the ImpersonatingMitmManager to generate EC keys and to use the EC RootCertificateGenerator
    ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
            .rootCertificateSource(rootCertificateGenerator)
            .serverKeyGenerator(new ECKeyGenerator())
            .build();
    // when using BrowserMob Proxy:
    BrowserMobProxy proxy = new BrowserMobProxyServer();
  //  proxy.setMitmManager(ImpersonatingMitmManager.builder().trustAllServers(true).build());

    proxy.setMitmManager(mitmManager);
    proxy.setChainedProxy(new InetSocketAddress("proxy", 8080));  
    proxy.setTrustAllServers(true);
    proxy.start(0);
    
    
    // get the Selenium proxy object
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
String hostIp = Inet4Address.getLocalHost().getHostAddress();

System.out.println();
seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());

    // configure it as a desired capability
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("chrome");
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
        capabilities.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
        capabilities.setCapability(CapabilityType.ForSeleniumServer.AVOIDING_PROXY, true);
                        capabilities.setCapability(CapabilityType.ForSeleniumServer.ONLY_PROXYING_SELENIUM_TRAFFIC, true);
                  capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    // start the browser up
    File inputFile = new File("C:\\chromedriver_win32\\chromedriver.exe");
    System.setProperty("webdriver.chrome.driver",inputFile.getCanonicalPath());
    
    ChromeDriverService service =new ChromeDriverService.Builder().withWhitelistedIps("").withVerbose(true).build();
   
    @SuppressWarnings("deprecation")
WebDriver driver = new ChromeDriver(capabilities);
    //System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
   
    // enable more detailed HAR capture, if desired (see CaptureType for the complete list)
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
    // start the proxy
    
    System.out.println(proxy.getPort());
    // create a new HAR with the label "yahoo.com"
    proxy.newHar("qacand.com");

    // open yahoo.com
    driver.get("https://www.baidu.com/"); 
    //driver.wait(3000);
    driver.findElement(By.name("q")).sendKeys("selenium");;

    // get the HAR data
    Har har = proxy.getHar();
    FileOutputStream fos = new FileOutputStream("C:\\Work\\HAR-Information-baidu.har");
        har.writeTo(fos);
        proxy.stop();
        driver.close();
  }

linda xu

unread,
Mar 18, 2021, 5:54:32 AM3/18/21
to BrowserMob Proxy
Screenshot 2021-03-18 175332.png
Reply all
Reply to author
Forward
0 new messages