本篇講述如何修改 fiddler script腳本實現(xiàn)以下功能
請求轉(zhuǎn)發(fā):替換請求的host
請求保存:保存請求的數(shù)據(jù)到本地文件
1.點擊Rules -->Custoomize Rules打開fiddler script
2.在OnBeforeRequest方法里添加如下代碼修改請求的host 愧哟,將請求的host為www.baidu.com的請求轉(zhuǎn)發(fā)至www.taobao.com
var origin_host="www.baidu.com";
var replace_host="www.taobao.com";
if(oSession.host==origin_host){
oSession.fullUrl = oSession.fullUrl.Replace(origin_host,replace_host);
}
3.在OnBeforeRequest方法里添加如下代碼,將含有www.baidu.com的請求數(shù)據(jù)保存至D:\http\Interface.txt文件里
if (oSession.fullUrl.Contains("www.baidu.com"))
{
var fso;
var file;
fso = new ActiveXObject("Scripting.FileSystemObject");
file = fso.OpenTextFile("D:\\http\\Interface.txt",8 ,true, -2);
file.writeLine("Request url:" + oSession.url);
file.writeLine("Request header:" + "\n" + oSession.oRequest.headers);
file.writeLine("Request body:" + oSession.GetRequestBodyAsString());
file.writeLine("\n");
file.close();
}