右键解决方案选项卡,选择【管理解决方案的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 );
}
}
可以给他绑定事件,之后会提示安装证书
现在你就可以对相应请求进行处理了~