2017-06-12 2 views
1

BrowserMobプロキシライブラリ(net.lightbody.bmp)を使用して、一部のデフォルトWebサイト(たとえば、 "https://default.com")からのHTTP要求を傍受しようとしています。BrowserMob。 httpClientを通じてBrowserMobProxyを設定する方法

BrowserMobProxy proxy = new BrowserMobProxyServer(); 
proxy.start(9091, InetAddress.getByName("127.0.0.1"), InetAddress.getByName("default.com")); 

その後、私はフィルタリング要求

proxy.addRequestFilter(new RequestFilter() { 
     @Override 
     public HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {}... 

ための匿名クラスを作成しますが、何も起こりません。

答えて

0
//start the proxy 
    BrowserMobProxy bmproxy = new BrowserMobProxyServer(); 
    bmproxy.start(); // specify the port and address here. 

    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(bmproxy); 

    // configure it as a desired capability 
    DesiredCapabilities capabilities = new DesiredCapabilities();   

    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy) 

    // start the browser up 
    WebDriver driver = new ChromeDriver(capabilities); 

    // enable more detailed HAR capture, if desired (see CaptureType for the complete list) 
    bmproxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT); 

    // create a new HAR with the label "ebay.de" 
    bmproxy.newHar("ebay.de"); 

    // open ebay.de 
    driver.get("http://ebay.de"); 

    // get the HAR data 
    Har har = bmproxy.getHar(); 
    File harFile = new File("<filename>.har"); 
    har.writeTo(harFile); 

    driver.quit(); 

希望します。

関連する問題