Mateusz Sobczak
Mateusz Sobczak

Reputation: 1613

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

Upvotes: 0

Views: 1329

Answers (1)

DonLeo
DonLeo

Reputation: 355

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.

Upvotes: 1

Related Questions