【问题标题】:BrowserMob. How to configure BrowserMobProxy through httpclient浏览器。如何通过httpclient配置BrowserMobProxy
【发布时间】:2017-06-12 14:30:34
【问题描述】:

我正在尝试使用 BrowserMob 代理库 (net.lightbody.bmp) 来拦截来自某些默认网站的 http 请求(例如:“https://default.com”),我的问题是如何做到这一点?

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) {}...

但什么也没发生。

【问题讨论】:

    标签: java browsermob browsermob-proxy


    【解决方案1】:
        //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();
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2016-12-30
      • 2020-03-15
      相关资源
      最近更新 更多