日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

使用FiddlerCore来截取替换Http请求中的网页内容

發布時間:2025/7/14 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用FiddlerCore来截取替换Http请求中的网页内容 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

做過測試的應該都知道Fiddler,它可以很方便截取Internet上的網頁替換成本地的,或者修改其中的一部分內容后呈現。簡單地說就是可能監測所有HTTP連接,設置斷點,胡亂修改。是測試調試的一件利器。
使用Fiddler的開放組件,我們可以將其集成到自己的程序中,如生成flash/silverlight所需要的crossdomain.xml,clientaccesspolicy.xml安全文件等:
Fiddler的API: http://www.fiddler2.com/fiddler/dev/ScriptSamples.asp

下面是一個小例子:自動生成所有的silverlight安全策略文件:

using System;
using Fiddler;

namespace AccessPolicyTool
{
????class Program
????{
????????const string PolicyXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<access-policy>
????<cross-domain-access>
????????<policy>
????????????<allow-from http-request-headers=""*"">
????????????????<domain uri=""http://*""/>
????????????</allow-from>
????????????<grant-to>
????????????????<resource path=""/"" include-subpaths=""true""/>
????????????</grant-to>
????????</policy>
????</cross-domain-access>
</access-policy>";

????????//find and replace the client access policy file.
????????static void Main(string[] args)
????????{
????????????//List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();

????????????Fiddler.FiddlerApplication.BeforeRequest += new SessionStateHandler(FiddlerApplication_BeforeRequest);
????????????Fiddler.FiddlerApplication.BeforeResponse += new Fiddler.SessionStateHandler(FiddlerApplication_BeforeResponse);

????????????Fiddler.FiddlerApplication.Startup(8877, FiddlerCoreStartupFlags.Default);
????????????Console.ReadKey();
????????????Fiddler.FiddlerApplication.Shutdown();
????????}

????????static void FiddlerApplication_BeforeRequest(Session oSession)
????????{
????????????Console.WriteLine("FiddlerApplication_BeforeRequest");

????????????if (oSession.fullUrl.IndexOf("clientaccesspolicy.xml") > 0)
????????????{
????????????????oSession.bBufferResponse = true;
????????????}
????????}

????????//find and replace the client access policy file.
????????static void FiddlerApplication_BeforeResponse(Fiddler.Session oSession)
????????{
????????????if (oSession.fullUrl.IndexOf("clientaccesspolicy.xml") > 0)
????????????{
????????????????Console.WriteLine(oSession.fullUrl);

????????????????oSession.utilDecodeResponse();
????????????????oSession.utilSetResponseBody(PolicyXml);

????????????????oSession.oResponse.headers.HTTPResponseCode = 200;
????????????????oSession.oResponse.headers.HTTPResponseStatus = "200 OK";
????????????????oSession.oResponse.headers["Content-Type"] = "text/xml";
????????????????oSession.oResponse.headers.Remove("WWW-Authenticate");
????????????}
????????}
????}
}

?

FiddlerCore 修改HTTP返回結果

發了封郵件給官網,問題解決了。?
在BeforeRequest事件中設置Session.bBufferResponse?=?true?就可以了。

總結

以上是生活随笔為你收集整理的使用FiddlerCore来截取替换Http请求中的网页内容的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。