简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM