如何使用fiddlercore编辑HTTP请求C#

时间:2012-12-14 09:27:07

标签: c# http networking post request

我希望能够做什么:在将HTTP请求发送到服务器之前编辑它们

用户在浏览器中导航到他们选择的网页>他们遇到了他们想要编辑的请求>他们编辑请求然后将其发送到服务器而不是原始服务器。

到目前为止我做了什么:我已经捕获了请求,现在我需要帮助找到编辑它的代码。这是我到目前为止捕获请求的代码:

    Fiddler.FiddlerApplication.BeforeRequest += sess =>
    {
        //Code to detect user specified URL here
    }

我可以在实际发送之前编辑请求吗?如果只能使用FiddlerCore API完成,那么我将不胜感激,但如果需要,我愿意下载更多二进制文件。

附加说明:我已经尝试过使用二进制写入器,将二进制文件复制到内存流中然后将其复制回来,这些方法都不适用于我。此外,当我尝试一些方法我的应用程序只是挂起,并没有回应像按下X。

也许我只是不好解释我想要实现的目标似乎是我唯一的好回答:/

如果请求读取字符串“hello world”,那么我希望用户能够将REQUEST更改为“hello there”

2 个答案:

答案 0 :(得分:1)

我犯了这样一个错误的错误,我以为RequestBody是只读的!事实证明我可以简单地编辑这样的响应:

    session.RequestBody = myBytes;

对此我真的很恼火!

答案 1 :(得分:0)

在演示应用中,添加代理显示为:

    Fiddler.FiddlerApplication.BeforeResponse += delegate(Fiddler.Session oS) {
        // Console.WriteLine("{0}:HTTP {1} for {2}", oS.id, oS.responseCode, oS.fullUrl);

        // Uncomment the following two statements to decompress/unchunk the
        // HTTP response and subsequently modify any HTTP responses to replace 
        // instances of the word "Microsoft" with "Bayden". You MUST also
        // set bBufferResponse = true inside the beforeREQUEST method above.
        //
        //oS.utilDecodeResponse(); oS.utilReplaceInResponse("Microsoft", "Bayden");
    };