找回密码
 立即注册
首页 业界区 安全 Fiddler自定义规则保存图片和提示The system proxy was ...

Fiddler自定义规则保存图片和提示The system proxy was changed自动重连

郜庄静 2025-11-26 12:10:00
1、打开Fiddler ,找到 规则(Rules)-> 自定义规则(Customize Rules) 打开 规则代码。
  1.         static function OnDone(oSession: Session) {
  2.                 if (oSession.uriContains("https://www.xxx.com/xxxx")==false)
  3.                 {
  4.                             return;
  5.                 }
  6.                 //检查Content-Type
  7.                 if (oSession.ResponseHeaders["Content-Type"]!=null || oSession.ResponseHeaders["content-type"]!=null)
  8.                 {
  9.                         //避免不规范标头
  10.                         var contentType=oSession.ResponseHeaders["Content-Type"];
  11.                         if (String.IsNullOrEmpty(contentType) )
  12.                                 contentType=oSession.ResponseHeaders["content-type"];
  13.             
  14.                         //判定请求是否图片
  15.                         if (contentType.Contains("image"))
  16.                         {
  17.                                 //确定文件名(保存用)
  18.                                 var fileName="";
  19.                                 var fileIndex =    oSession.RequestHeaders.RequestPath.LastIndexOf ("/");
  20.                                 if (fileIndex>0)
  21.                                         fileName =    oSession.RequestHeaders.RequestPath.Substring (fileIndex+1);
  22.                
  23.                                 //如果文件名非法(名称含非法字符)
  24.                                 if(fileName.IndexOf('?')>0 || fileName.IndexOf('&') )
  25.                                         fileName=String.Empty;
  26.                                 //输出日志(在Fiddler 主窗口,日志处输出)
  27.                                 //FiddlerObject.log("Content-Type:"+ contentType +" RequestPath:"+oSession.RequestHeaders.RequestPath);
  28.                
  29.                                 //如果文件名为Null,自行创建一个文件名(Guid)
  30.                                 if (String.IsNullOrEmpty( fileName))
  31.                                 {
  32.                                         fileName=Guid.NewGuid().ToString();
  33.                                         var extName=    contentType.Replace("image/","");
  34.                                         fileName=fileName+"."+extName;
  35.                                 }
  36.                
  37.                                 //太小的图片不要,比如站位图片(自行调节)
  38.                                 if (oSession.ResponseBody.Length>100)
  39.                                 {
  40.                                         //指定保存位置
  41.                                         var saveDir="D:\\fiddlerimage\";
  42.                                         //不存在则创建文件夹
  43.                                         if (!System.IO.Directory.Exists(saveDir))
  44.                                                 System.IO.Directory.CreateDirectory(saveDir);
  45.                     
  46.                                         //保存响应流
  47.                                         oSession.SaveResponseBody(saveDir+fileName);
  48.                                         //写日志
  49.                                         FiddlerObject.log("[文件保存]:"+fileName)
  50.                                 }
  51.                         }
  52.                 }
  53.         }
  54.                        
复制代码
  
 
 
Fiddler一直提示The system proxy was changed,click to reenable fiddler capture

 解决办法:进入到Fiddler-->Rules-->Customize Rules</p>1.在main()方法上方添加:
static function DoReattach(o: Object, ea: EventArgs)
{
ScheduledTasks.ScheduleWork("reattach", 1000, innerReattach);
}

static function innerReattach()
{
FiddlerApplication.UI.actAttachProxy();
}

static function OnRetire()
{
FiddlerApplication.oProxy.remove_DetachedUnexpectedly(DoReattach);
}
 
2.在main()方法中添加:
FiddlerApplication.oProxy.add_DetachedUnexpectedly(DoReattach);
1.png

 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册