fiddler⾼级⽤法,⼿动修改替换请求和响应⼿动修改fiddle的请求和响应
Rules->Custon Rules,或按Ctrl+R键,编辑 CustomRules.js 代码⽂件,在OnBeforeRequest函数⾥修改代码:添加请求 header(头)
oSession.oRequest["NewHeaderName"] = "New header(头) value";
删除响应 header(头)
oSession.oResponse.headers.Remove("Set-Cookie");
改变请求参数
if (oSession.PathAndQuery=="/version1.css") {
oSession.PathAndQuery="/version2.css";
}
替换请求url指向
if (oSession.HostnameIs("www.baidu")) {
oSession.hostname="le";
}
替换请求url指向和端⼝
if (oSession.host=="www.baidu:8080") {
oSession.host="test.baidu:9090";
}
替换请求url指向包含HTTPS tunnels
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "ample:443")) { oSession.PathAndQuery = "ample:443";
}
if (oSession.HostnameIs("ample")) oSession.hostname = "ample";
替换⽹页和静态⽂件
if (oSession.url=="ample/live.js") {
oSession.url = "ample/workinprogress.js";
}
阻⽌上载HTTP Cookie
oSession.oRequest.headers.Remove("Cookie");
解压缩并取消解压HTTP响应
// Remove any compression or chunking from the response in order to make it easier to manipulate
oSession.utilDecodeResponse();
在HTML中搜索和替换
if (oSession.HostnameIs("www.baidu") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){ oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}
响应HTML的不区分⼤⼩写搜索.
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/html") && oSession.utilFindInResponse("searchfor", false)>-1){ oSession["ui-color"] = "red";
}
删除所有DIV标记(以及DIV标记内的内容)
// If content-type is HTML, then remove all DIV tags
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.sponseBodyBytes);exists的用法
// Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi;
oBody = place(oRegEx, "");
// Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);
}
模拟HTTP基本⾝份验证(要求⽤户在显⽰web内容之前输⼊密码。)
if ((oSession.HostnameIs("ample")) &&
!oSession.oRequest.headers.Exists("Authorization"))
{
// Prevent IE's "Friendly Errors Messages" from hiding the error message by making response body l
onger than 512 chars. var oBody = "<html><body>[Fiddler] Authentication Required.<BR>".PadRight(512, ' ') + "</body></html>";
oSession.utilSetResponseBody(oBody);
// Build up the headers
oSession.oResponse.headers.HTTPResponseCode = 401;
oSession.oResponse.headers.HTTPResponseStatus = "401 Auth Required";
oSession.oResponse["WWW-Authenticate"] = "Basic realm=\"Fiddler (just hit Ok)\"";
oResponse.headers.add("Content-Type", "text/html");
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。