.NET framework利用Fiddler Core5获取http/https请求

右键解决方案选项卡,选择【管理解决方案的NuGet程序包】

 需要用nuget的程序源进行搜索,没有设置,在右上角点击

 

 安装FillderCore5

 安装成功后,引用Fillder

using Fiddler;

然后设置代理,

        var settings = new FiddlerCoreStartupSettingsBuilder()
           .RegisterAsSystemProxy()
           .DecryptSSL()
           .ListenOnPort(8888)
           .Build();
            // 启动代理
            FiddlerApplication.Startup(settings);
            if (!CertMaker.rootCertExists())
            {
                // 创建根证书并添加到受信任的根证书存储中
                if (CertMaker.createRootCert())
                {
                    CertMaker.trustRootCert();
                }
            }
            // 在程序退出时关闭 FiddlerCore 代理
            AppDomain.CurrentDomain.ProcessExit += (exitSender, exitEventArgs) =>
            {
                FiddlerApplication.Shutdown();
            };
            // 注册 BeforeResponse 事件
             FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
        }
        //----------------------------------------------------------------------------------------
        // BeforeResponse 事件处理程序
        private static void FiddlerApplication_BeforeResponse(Session oSession)
        {
            // 获取请求返回的数据
            string sessionString = oSession.GetResponseBodyAsString();
            // 判断请求的 URL
            if (oSession.fullUrl.Contains("exmaple.com"))
            {
                string sessionString = oSession.GetResponseBodyAsString();
                // 设置修改后的响应数据为指定的字符串
                string modifiedResponseData = "{\"ret\":200,\"state\":{\"need_reset_pswd\":false,\"not_bind_pswd\":false},\"msg\":\"OK\",\"data\":{\"a1\":90,\"a2\":497}}";
                // 设置修改后的响应数据
                oSession.utilSetResponseBody(modifiedResponseData );
            }
        }

可以给他绑定事件,之后会提示安装证书

 现在你就可以对相应请求进行处理了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值