【问题标题】:Executing a script from Fiddler Autoresponder从 Fiddler Autoresponder 执行脚本
【发布时间】:2020-01-06 06:25:26
【问题描述】:

我正在尝试使用 Fiddler Autoresponder 规则在本地测试脚本,并且我有一个端点,该端点在响应中包含请求正文的哈希。我想我可以从自动回复器中触发一个脚本并计算哈希值并构建响应,但要弄清楚如何去做是非常困难的。

据我所知,AutoResponder 支持脚本,但几乎没有文档。我能找到的唯一参考是 Fiddler 论坛 (https://www.telerik.com/forums/script-in-autoresponder) 中的这篇文章,但我不知道文档中的详细信息来自何处。

我可以让脚本运行,但它似乎在发送请求之前运行,我不知道如何让它正常执行请求(或从文件加载响应,或填充响应正文来自脚本),然后执行我的代码以将哈希添加为标题。

我对 Session 对象有点搞砸了,但找不到任何明显的东西。是否有更好的 Fiddler 文档实际上是最新的?

【问题讨论】:

    标签: fiddler


    【解决方案1】:

    这是一个构造响应的函数示例,该响应包含来自请求的动态信息。

    public static function UrbanDictionaryBlocker(oS: Session)
    {   
        if (oS.HTTPMethodIs("GET")) // avoid HTTPS errors
        {
            oS.utilCreateResponseAndBypassServer();
            oS.ResponseBody = System.Text.Encoding.UTF8.GetBytes("stop browsing urban dictionary at work: " + oS.fullUrl);
        }
    }
    

    我编写了一个关联规则,将包含“urbandictionary”的 URL 映射到此函数。

    我是怎么想到的:

    我通过设置 Fiddler extension develoment in Visual Studio 解决了这个问题,这为 Fiddler API 提供了更好的智能感知。使用 go to definition,我可以方便地查看 Session 类中所有方法的列表。

    例子:

    ...
            [CodeDescription("Returns true if request URI contains the specified string. Case-insensitive.")]
            public bool uriContains(string sLookfor);
            [CodeDescription("Copy an existing Session's response to this Session, bypassing the server if not already contacted")]
            public void utilAssignResponse(Session oFromSession);
            [CodeDescription("Copy an existing response to this Session, bypassing the server if not already contacted")]
            public void utilAssignResponse(HTTPResponseHeaders oRH, byte[] arrBody);
            [CodeDescription("Use BZIP2 to compress the response body. Throws exceptions to caller.")]
            public bool utilBZIP2Response();
            [CodeDescription("Apply Transfer-Encoding: chunked to the response, if possible.")]
            public bool utilChunkResponse(int iSuggestedChunkCount);
            [CodeDescription("Call inside OnBeforeRequest to create a Response object and bypass the server.")]
            public void utilCreateResponseAndBypassServer();
            [CodeDescription("Removes chunking and HTTP Compression from the Request. Adds or updates Content-Length header.")]
            public bool utilDecodeRequest();
            public bool utilDecodeRequest(bool bSilent);
            [CodeDescription("Removes chunking and HTTP Compression from the response. Adds or updates Content-Length header.")]
            public bool utilDecodeResponse();
    ...
    

    然后我猜想utilCreateResponseAndBypassServer 是完成这项工作的工具。

    【讨论】:

    • 谢谢!我还发现您可以使用oS.LoadResponseFromStream(new MemoryStream(), null); 作为回避请求过程的简单方法。从那里您可以根据需要设置状态代码和各种其他属性。我喜欢使用 Visual Studio 以获得更好的智能感知的建议,下次我会尝试一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多