简体   繁体   English

我如何使用Fiddlercore编辑HTTP请求C#

[英]How can i edit a HTTP a request C# using fiddlercore

What I want to be able to do: Edit HTTP Requests before they are sent off to the server 我想要做的是:在将HTTP请求发送到服务器之前先对其进行编辑

User navigates to a webpage of their choice in their browser > They encounter a request they wish to edit > they edit the request and then that gets sent to the server instead of the original one. 用户在浏览器中导航到他们选择的网页>遇到他们希望编辑的请求>编辑请求,然后该请求被发送到服务器,而不是原始请求。

What I have done so far: I have captured the request, now I need help finding the code to edit it. 到目前为止,我已经完成了什么:我已经捕获了请求,现在我需要帮助查找代码来对其进行编辑。 Here is my code for capturing the request so far: 这是到目前为止我捕获请求的代码:

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

Is it possible for me to edit the request before it is actually sent? 我可以在实际发送请求之前对其进行编辑吗? If it can be done using the FiddlerCore API only then I'd be grateful, although I am willing to download more binaries if required. 如果只能使用FiddlerCore API做到这一点,那么我将不胜感激,尽管我愿意在需要时下载更多的二进制文件。

Additional notes: I have tried streamwriters, binary writers, copy the respose into a memory stream edit it then copy it back, none of those methods work for me. 附加说明:我尝试过streamwriters,binary writers,将重生文件复制到内存流中进行编辑,然后再复制回去,这些方法都不适合我。 Also when I try some methods my app just hangs and doesn't respond to things like pressing the X. 另外,当我尝试某些方法时,我的应用程序只是挂起,并且不响应按X的操作。

Maybe I'm just bad at explaining what I'm trying to achieve seems the only good answer I have has been about reponses :/ 也许我只是在解释我试图达到的目标上很不好,似乎我唯一一直以来对响应的好答案是:/

If the request reads the string "hello world" then I'd like the user to be able to change the REQUEST to say "hello there" 如果请求读取字符串“ hello world”,那么我希望用户能够将REQUEST更改为“ hello there”

Such a noobish mistake I made, I thought that RequestBody was read only! 我犯了一个如此愚蠢的错误,我认为RequestBody是只读的! Turns out I could have simply edited the response like this: 原来我可以像这样简单地编辑响应:

    session.RequestBody = myBytes;

Really annoyed at myself for this! 为此我真的很生气!

In the demo app, adding the delegate is shown as: 在演示应用程序中,添加代理显示为:

    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");
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM