java - 浏览器Mob。如何通过httpclient配置BrowserMobProxy

标签 java browsermob browsermob-proxy

我正在尝试使用 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) {}...

但什么也没发生。

最佳答案

    //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();

希望有帮助。

关于java - 浏览器Mob。如何通过httpclient配置BrowserMobProxy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44501992/

相关文章:

Java 编码标准和多个 IF

java - Ant中的echo目标描述

java - 没有 faces-config 的 JSF 2.0 国际化

java - 不幸的是我的第一个应用程序在模拟器中停止了

appium - 原生应用中 Appium 的 HTTP 代理?

python - 如何在 Python 上使用 selenium webdriver 和 browsermob 代理捕获网络流量?

browsermob 代理 'server is refusing connections' 错误

java - 使用 Selenium Java 的 BrowserMobProxy

Java:更改外部库 Maven 依赖项的日志级别

java - 使用 BrowserMobProxy、Selenium、Firefox、marionette/gecko 获取请求和响应