在FiddlerScript的里面添加以下代码即可
static function OnDone(oSession: Session) {
// var host=oSession.RequestHeaders["Host"];
var url=oSession.fullUrl.ToString();
//xxx为需要保存的接口
if(url.Contains("XXX")){
//检查Content-Type
var fso;
var file;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.OpenTextFile("E:/haokan/mmb_hy.txt",8 ,true);
//file.writeLine("Request-host:" + oSession.host);
//file.writeLine("Request-header:" + "\n" + oSession.oRequest.headers);
//file.writeLine("Request-body:" + + "\n"+oSession.GetRequestBodyAsString());
//file.writeLine(url)
file.writeLine(oSession.GetResponseBodyAsString().ToString());
file.close();
}
//image.com修改为你需要下载图片的前缀即可
if(oSession.uriContains("image.com")){
//检查Content-Type
if (oSession.ResponseHeaders["Content-Type"]!=null || oSession.ResponseHeaders["content-type"]!=null)
{
//避免不规范标头
var contentType=oSession.ResponseHeaders["Content-Type"];
if (String.IsNullOrEmpty(contentType) )
contentType=oSession.ResponseHeaders["content-type"];
//判定请求是否图片
if (contentType.Contains("image"))
{
//确定文件名(保存用)
var fileName="";
var fileIndex = oSession.RequestHeaders.RequestPath.LastIndexOf ("/");
if (fileIndex>0)
fileName = oSession.RequestHeaders.RequestPath.Substring (fileIndex+1);
//如果文件名非法(名称含非法字符)
if(fileName.IndexOf('?')>0 || fileName.IndexOf('&') )
fileName=String.Empty;
//输出日志(在Fiddler 主窗口,日志处输出)
//FiddlerObject.log("Content-Type:"+ contentType +" RequestPath:"+oSession.RequestHeaders.RequestPath);
//如果文件名为Null,自行创建一个文件名(Guid)
if (String.IsNullOrEmpty( fileName))
{
fileName=Guid.NewGuid().ToString();
var extName= contentType.Replace("image/","");
fileName=fileName+"."+extName;
}
//太小的图片不要,比如站位图片(自行调节)
if (oSession.ResponseBody.Length>1000000)
{
//指定保存位置
var saveDir="E:\\video\\头像\\";
//不存在则创建文件夹
if (!System.IO.Directory.Exists(saveDir))
System.IO.Directory.CreateDirectory(saveDir);
//保存响应流
oSession.SaveResponseBody(saveDir+fileName);
//写日志
FiddlerObject.log("[文件保存]:"+fileName)
}
}
}}
}