【问题标题】:How to edit body before send request with Fiddler(script)如何在使用 Fiddler(脚本)发送请求之前编辑正文
【发布时间】:2021-01-12 17:10:05
【问题描述】:

如何在使用 Fiddler(脚本)发送请求之前编辑正文

在我的情况下路径 /login 有身体 用户名:xxx 通过:xxxx

如何在发送发送请求之前编辑用户密码

【问题讨论】:

  • 嗨!欢迎来到 Stackoverflow!请展示您的尝试,以便我们为您提供帮助!
  • 我不知道设置 req boby sir 的命令
  • 我可以通过 oSession.oRequest["NewHeaderName"] = "New header value";但无法设置正文请求
  • 好吧,因为我不知道你在寻找什么,所以这可能不适合你。无论如何,通过谷歌快速查找给了我这个:jonathanblog2000.blogspot.com/2013/09/…

标签: fiddler fiddler-dev


【解决方案1】:

要在 Fiddler 经典版中修改请求,请使用 OnBeforeResponse 函数。要替换 HTTP 请求正文中的用户名和密码(不在标头中,例如 BASIC auth),您可以使用 utilReplaceInRequest 方法在文本级别执行搜索和替换:

static function OnBeforeResponse(oSession: Session) {
    // check if the requests is to the correct hosts and path
    if (oSession.HostnameIs("www.example.org") && oSession.PathAndQuery.Contains("/login")) {
        oSession.utilDecodeResponse();
        oSession.utilReplaceInRequest("username: xxx", "username: newusername");
        oSession.utilReplaceInRequest("pass: xxxx", "pass: newpassword");
    }
}

或者,您可以使用标准 .Net String methods 获取正文作为文本并根据需要对其进行操作:

    if (oSession.HostnameIs("www.example.org") && oSession.PathAndQuery.Contains("/login")) {
        oSession.utilDecodeResponse();
        var body = oSession.GetRequestBodyAsString();
        // use .Net String manipulation methods to find and replace text in the body
        oSession.utilSetRequestBody(body);
    }

【讨论】:

  • 当我不知道我想像这样设置的对象的值时如何设置 obj["username"] = "teeraphong" 不使用替换方法先生,因为我不知道值替换
【解决方案2】:
static function OnBeforeRequest(oSession: Session) {
    var loginDomain = 'www.testlogin.org';  
    var loginPath = '/login';
    var username;
    var password;
    var strBody
    
    if (username == null && oSession.uriContains(loginDomain) && 
        oSession.uriContains(loginPath))
    {

        username = FiddlerObject.prompt("Enter user name: ");
        password = FiddlerObject.prompt("Enter password: ");
        strBody='username: ' + username + ' pass: ' + password;
        //encode the body to handle special characters in the password
        //password "P&ssword=secure"    will be    "P%26ssword%3Dsecure"                                            
        strBody=Utilities.UrlEncode(strBody);
        oSession.utilSetRequestBody(strBody);
    }

//... the rest of the OnBeforeRequest function
}

这将打开 2 个提示窗口以输入用户名和密码 在浏览器中输入登录 URL 并执行请求后。提示可能不会在浏览器前弹出,您可能需要将焦点切换到 fiddler 才能使用提示窗口

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    相关资源
    最近更新 更多