有人熟悉在 Java 中使用HarLib吗?我正在尝试从 .HAR 文件中获取“响应”数据并将其输出到屏幕。
类中有一个getResponse()
方法HarEntry
,但是我不确定如何根据主页上的示例来实现它:
来自网站的样本:
import edu.umass.cs.benchlab.har.*;
File f = new File(fileName);
HarFileReader r = new HarFileReader();
HarFileWriter w = new HarFileWriter();
try
{
System.out.println("Reading " + fileName);
HarLog log = r.readHarFile(f);
// Access all elements as objects
HarBrowser browser = log.getBrowser();
HarEntries entries = log.getEntries();
List<HarPage> pages = log.getPages().getPages();
for (HarPage page : pages)
{
System.out.println("page start time: "
+ ISO8601DateFormatter.format(page.getStartedDateTime()));
System.out.println("page id: " + page.getId());
System.out.println("page title: "+page.getTitle());
}
// Once you are done manipulating the objects, write back to a file
System.out.println("Writing " + fileName + ".test");
File f2 = new File(fileName + ".test");
w.writeHarFile(log, f2);
}
catch (JsonParseException e)
{
e.printStackTrace();
fail("Parsing error during test");
}
catch (IOException e)
{
e.printStackTrace();
fail("IO exception during test");
}