手動修改fiddle的請求和響應
Rules->Custon Rules,或按Ctrl+R鍵,編輯 CustomRules.js 代碼文件,在OnBeforeRequest函數裏修改代碼:css
添加請求 header(頭)html
oSession.oRequest["NewHeaderName"] = "New header(頭) value";
刪除響應 header(頭)web
oSession.oResponse.headers.Remove("Set-Cookie");
改變請求參數less
if (oSession.PathAndQuery=="/version1.css") { oSession.PathAndQuery="/version2.css"; }
替換請求url指向函數
if (oSession.HostnameIs("www.baidu.com")) { oSession.hostname="www.google.com"; }
替換請求url指向和端口ui
if (oSession.host=="www.baidu.com:8080") { oSession.host="test.baidu.com:9090"; }
替換請求url指向包含HTTPS tunnelsgoogle
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "www.example.com:443")) {
oSession.PathAndQuery = "beta.example.com:443";
}url
if (oSession.HostnameIs("www.example.com")) oSession.hostname = "beta.example.com";spa
替換網頁和靜態文件code
if (oSession.url=="www.example.com/live.js") { oSession.url = "dev.example.com/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.com") && 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.GetString(oSession.responseBodyBytes); // Replace all instances of the DIV tag with an empty string var oRegEx = /<div[^>]*>(.*?)<\/div>/gi; oBody = oBody.replace(oRegEx, ""); // Set the response body to the div-less string oSession.utilSetResponseBody(oBody); }
模擬HTTP基自己份驗證(要求用戶在顯示web內容以前輸入密碼。)
if ((oSession.HostnameIs("www.example.com")) && !oSession.oRequest.headers.Exists("Authorization")) { // Prevent IE's "Friendly Errors Messages" from hiding the error message by making response body longer 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"); }