日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

做過測試的應(yīng)該都知道Fiddler,它可以很方便截取Internet上的網(wǎng)頁替換成本地的,或者修改其中的一部分內(nèi)容后呈現(xiàn)。簡單地說就是可能監(jiān)測所有HTTP連接,設(shè)置斷點(diǎn),胡亂修改。是測試調(diào)試的一件利器。
使用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返回結(jié)果

發(fā)了封郵件給官網(wǎng),問題解決了。?
在BeforeRequest事件中設(shè)置Session.bBufferResponse?=?true?就可以了。

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。