javaseleniumselenium-webdriverbrowsermobhar

Get only POST request/response in BrowserMob in Java


It is possible to filter all har object and get only POST request/response? Maybe during initialized BrowserMobProxyServer is way to do it? I need to save har object into file and upload into har viewer.

Har har = proxyServer.getHar();

Solution

  • I don't know if you can do it with ProxyServer configuration, but I'm sure you can filter requests like this:

    Har har = proxyServer.getHar();
    try {
        har.getLog().getEntries().removeIf(x-> !x.getRequest().getMethod().equals("POST"));
        har.writeTo(new File("har.json"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    It will create new file named "har.json" with only POSTs.