先来看一张自动保存的请求片段
重点来了,下面是实现的js代码
操作步骤
- Fiddler菜单 >> Rules >> Customize Rules
- 如果提示没有下载Fiddler ScriptEditor则按提示下载后进入下一步操作
- 安装好Fiddler ScriptEditor后,就能打开Customize Rules.js文件
- 编辑Customize Rules.js文件,并保存
- 重启fiddler
保存Request
把下面代码贴在OnBeforeRequest()
方法末尾
//过滤无关请求,只关注特定请求
if (oSession.fullUrl.Contains("szhome.com"))
{
var fso;
var file;
fso = new ActiveXObject("Scripting.FileSystemObject");
//文件保存路径,可自定义
file = fso.OpenTextFile("D:\Fiddler Sessions\Sessions.txt",8 ,true, true);
file.writeLine("Request url: " + oSession.url);
file.writeLine("Request header:" + "
" + oSession.oRequest.headers);
file.writeLine("Request body: " + oSession.GetRequestBodyAsString());
file.writeLine("
");
file.close();
}
保存Response
把下面代码贴在OnBeforeResponse()
方法末尾
//过滤无关请求,只关注特定请求
if (oSession.fullUrl.Contains("szhome.com"))
{
oSession.utilDecodeResponse();//消除保存的请求可能存在乱码的情况
var fso;
var file;
fso = new ActiveXObject("Scripting.FileSystemObject");
//文件保存路径,可自定义
file = fso.OpenTextFile("D:\Fiddler Sessions\Sessions.txt",8 ,true, true);
file.writeLine("Response code: " + oSession.responseCode);
file.writeLine("Response body: " + oSession.GetResponseBodyAsString());
file.writeLine("
");
file.close();
}