Fiddler 修改响应内容
1. 导入 FiddlerCore.dll 第三方库。
2. 开启侦听端口,FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.Default);
3. 设置响应可写,
FiddlerApplication.BeforeRequest += t>
{
if (t.uriContains("cnblogs"))
{
t.bBufferResponse = true;
}
};
4. 修改响应,
FiddlerApplication.BeforeResponse += t =>
{
if (t.fullUrl.Contains("cnblogs"))
{
var document = new HtmlDocument();
using (var stream = new MemoryStream(Encoding.GetEncoding(936).GetBytes(t.GetResponseBodyAsString())))
{
document.Load(stream);
}
var a = t.GetResponseBodyAsString();
document.LoadHtml(a.Replace("博客园", "博客论坛"));
using (var stream = new MemoryStream())
{
document.Save(stream, Encoding.UTF8);
t.ResponseBody = stream.ToArray();
}
}
};
5. 停用侦听(很重要),FiddlerApplication.Shutdown()。