如何在使用 Fiddler(脚本)发送请求之前编辑正文
在我的情况下,路径 /login 有正文用户名:xxx 通行证:xxxx
如何在发送发送请求之前编辑用户密码
如何在使用 Fiddler(脚本)发送请求之前编辑正文
在我的情况下,路径 /login 有正文用户名:xxx 通行证:xxxx
如何在发送发送请求之前编辑用户密码
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
}
在浏览器中输入登录 URL 并执行请求后,这将打开 2 个提示窗口以输入用户名和密码。提示可能不会在浏览器前面弹出,您可能需要将焦点切换到 fiddler 才能使用提示窗口
要在 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 方法根据需要对其进行操作:
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);
}