您好,您正在尝试使用browsermob代理+ selenium测试框架捕获HTTP POST请求中的实际POST数据。因此,基本上我正在使用selenium运行自动化测试,并且希望在测试期间捕获键/值对和HTTP POST请求的实际POST数据。使用以下逻辑,我只能捕获POST标题的键/值对,而不能捕获实际的POST数据(也称为表单字段id值)。有没有一种方法可以真正捕获POSTDATA (就像嗅探应用程序一样,比如firefox中的篡改/实时报头)?
ProxyServer proxyServer = null;
proxyServer = new ProxyServer(9101);
proxyServer.start();
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);
Proxy proxy = proxyServer.seleniumProxy();
proxy.setHttpProxy("localhost:9101");
//selenium test config code, omitted for brevity
proxyServer.addRequestInterceptor(new HttpRequestInterceptor() {
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
Header[] headers = request.getAllHeaders();
System.out.println("\nRequest Headers\n\n");
for(Header h : headers) {
System.out.println("Key: " + h.getName() + " | Value: " + h.getValue());
}
}
});我读到的另一种方法是在browsermob代理服务器中将以下标志配置为true:
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);然后输出实际的HAR文件:
Har har = proxyServer.getHar();
Date date = new Date();
har.writeTo(new File("c:\\tmp\\har_" + date.getTime()));要查看键/值对、POST数据和响应的实际内容...但是当我解析HAR文件的时候...我只能再次看到POST头的键/值对...无POST数据...无响应内容。不过,我只对实际的POST数据感兴趣。
发布于 2015-08-26 21:54:43
我也有同样的问题。作为解决方案,我捕获了所有数据,将HAR文件转换为JSON,然后只从JSON文件中过滤出POST请求。
https://stackoverflow.com/questions/11976571
复制相似问题