Get only POST request/response in BrowserMob in Java

1.2k views Asked by At

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

There are 1 answers

0
DonLeo On BEST ANSWER

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.