[TOC]
>[success] # 參數的總結
~~~
1.
~~~
>[danger] ##### 在請求頭中增加/更改參數
~~~
oSession.oRequest["NewHeaderName"] = "New header value";
~~~
* 效果圖

>[danger] ##### 新建cookies
~~~
oSession.oRequest.headers.Add("Cookie", "username=testname;testpassword=P@ssword1");
~~~
>[danger] ##### 清空請求頭指定參數
~~~
oSession.oResponse.headers.Remove("Set-Cookie");
~~~
>[danger] ##### 修改cookie
~~~
if (oSession.HostnameIs('www.example.com') &&
oSession.uriContains('pagewithCookie') &&
oSession.oRequest.headers.Contains("Cookie"))
{
var sCookie = oSession.oRequest["Cookie"];
// 用replace方法或者正則表達式的方法去操作cookie的string
sCookie = sCookie.Replace("cookieName=", "ignoreme=");
oSession.oRequest["Cookie"] = sCookie;
}
~~~
>[danger] ##### 利用腳本進行請求篡改(必須使用請求體的)
~~~
if(oSession.uriContains("www.baidu.com"))
{
// 獲取Request 中的body字符串
var strBody=oSession.GetRequestBodyAsString();
// 用正則表達式或者replace方法去修改string
strBody=strBody.replace("1111","2222");
// 彈個對話框檢查下修改后的body
FiddlerObject.alert(strBody);
// 將修改后的body,重新寫回Request中
oSession.utilSetRequestBody(strBody);
}
~~~
* 提供的上面縮寫的方法
~~~
oSession.utilReplaceInRequest("1111", "2222");
~~~
>[danger] ##### 更改相同服務器的請求
~~~
// 可以理解在同一個host
if (oSession.PathAndQuery=="/version1.css") {
oSession.PathAndQuery="/version2.css";
}
~~~
>[danger] ##### 更改host
~~~
if (oSession.HostnameIs("www.bayden.com")) {
oSession.hostname="test.bayden.com";
}
~~~
>[danger] ##### 更改端口
~~~
if (oSession.host=="www.bayden.com:8080") {
oSession.host="test.bayden.com:9090";
}
~~~
>[danger] ##### 更改重定向ip地址
~~~
// All requests for subdomain.example.com should be directed to the development server at 128.123.133.123
if (oSession.HostnameIs("subdomain.example.com")){
oSession.bypassGateway = true; // Prevent this request from going through an upstream proxy
oSession["x-overrideHost"] = "128.123.133.123"; // DNS name or IP address of target server
}
~~~
>[danger] ##### 鏈接跳轉重定向
~~~
if (oSession.url=="www.example.com/live.js") {
oSession.url = "dev.example.com/workinprogress.js";
}
~~~
>[danger] ##### 禁止請求時帶上cookies
~~~
oSession.oRequest.headers.Remove("Cookie");
~~~
>[danger] ##### 更改請求語言
~~~
oSession.oRequest["Accept-Language"]="he";
~~~
>[danger] ##### 禁止請求css
~~~
if (oSession.uriContains(".css")){
oSession["ui-color"]="orange";
oSession["ui-bold"]="true";
oSession.oRequest.FailSession(404, "Blocked", "Fiddler blocked CSS file");
}
~~~
>[success] # 響應 -- OnBeforeResponse
~~~
~~~
>[danger] ##### utilDecodeResponse -- 解壓響應信息
~~~
// Remove any compression or chunking from the response in order to make it easier to manipulate
oSession.utilDecodeResponse();
~~~
>[danger] ##### utilReplaceInResponse-- 更改響應中的html
~~~
if (oSession.HostnameIs("www.bayden.com") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('<b>','<u>');
}
~~~
>[dasnger] ##### -- 利用正則刪除響應中的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);
}
~~~
>[success] # 參考文檔
<a href="http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse"> 參考文章</a>