Fiddler (two) Script Usage

 

The previous blog [by] Fiddler tutorial, we understand the basic usage Fiddler, and now we take a look at Fiddler's advanced usage. Fiddler Script. Fiddler in the script allows us to automatically modify the content Http request and Response. Without having to manually go to the next "break" to modify the value of http Request or Response.

Fiddler author

Fiddler's author is Eric Lawrence is a master of character, currently working at Microsoft headquarters in Seattle. His blog is: http://www.ericlawrence.com/Eric/

Blog can be seen in his resume, as well as some photos of life.

 

How have problems to ask the author of Fiddler

Eric Lawrence built in the Google Groups discussion groups a Fiddler, the address is: https://groups.google.com/forum/?fromgroups#!forum/httpfiddler

Here the user Fiddler If you have any questions, you can direct this forum to ask Eric Law. Eric Law in general will soon get back to you. Before asking questions, search for the next. Because your problem is likely someone would have asked before.

 

About Fiddler Script

Fiddler includes a script file can automatically modify the Http Request and Response. So we do not need to manually underground "break" to modify,

In fact, it is a script file CustomRules.js 

位于: C:\Documents and Settings\[your user]\My Documents\Fiddler2\Scripts\CustomRules.js 下

You can also open the file in Fiddler in CustomRules.js, Fiddler start, click on the menu Rules-> Customize Rules ...

Fiddler Script official help documentation must be read, the address is: http://www.fiddler2.com/Fiddler/dev/ScriptSamples.asp

 

Fiddler Script is written in JScript.NET

I've never heard JScript.NET language, JScript may be an upgraded version of it. Write up a little bit similar to C #

 

Installation Fiddler Script Editor

You can directly notepadCustomRules.js file,

Highly recommended download Fiddler Script Editor address is: http://www.fiddler2.com/fiddler/fse.asp

Fiddler Script Editor provides syntax highlighting and IntelliSense function, as shown below:

 

The main method of CustomRules.js

// Request modify the content of this method, we use the most,

static function OnBeforeRequest(oSession: Session)

 

// modify the contents of Response in this method,

static function OnBeforeResponse(oSession: Session)

 

// Include Fiddler command in a method. In the bottom left of Fiddler interface QuickExec Box

static function OnExecAction(sParams: String[])

 

Fiddler added to the menu

Fiddler can simulate a variety of browser, you can click on the menu Rules-> User-Agents

But it does not seem Iphone 4S safari, we now add one. First check the Internet Iphone 4S safari of user-Agents, and then add the following code to the code on it

RulesStringValue(23, "Iphone 4S safari", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7")

 Save the script, restart Fiddler menu you can see more than a Iphone 4s

 

You can put your common operation, it is defined as a menu,

 

Modify the display style in Fiddler's Session

We can control Session style displayed in Fiddler in particular document is: http://www.fiddler2.com/Fiddler/dev/SessionFlags.asp

 

Put this script in OnBeforeRequest (oSession: Session) method under, and click "Save script", so that all cnblogs session will be displayed in red.

     if (oSession.HostnameIs("www.cnblogs.com")) {
oSession["ui-color"] = "red";
}

运行效果如

 

 

如何在Fiddler Script中修改Cookie

cookie其实就是request 中的一个header.

// 删除所有的cookie

oSession.oRequest.headers.Remove("Cookie");

 

// 新建cookie

oSession.oRequest.headers.Add("Cookie", "username=testname;testpassword=P@ssword1");


注意: Fiddler script不能直接删除或者编辑单独的一个cookie, 你需要用replace方法或者正则表达式的方法去操作cookie的string

复制代码
static function OnBeforeRequest(oSession: Session) 
{ 
     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; 
    } 
复制代码

 

如何在Fiddler Script中修改Request 中的body

方法一:

复制代码
static function OnBeforeRequest(oSession: Session) 
{ 
    if(oSession.uriContains("http://www.cnblogs.com/TankXiao/"))
    {
        // 获取Request 中的body字符串
        var strBody=oSession.GetRequestBodyAsString();
        // 用正则表达式或者replace方法去修改string
        strBody=strBody.replace("1111","2222");
        // 弹个对话框检查下修改后的body               
FiddlerObject.alert(strBody);
// 将修改后的body,重新写回Request中 oSession.utilSetRequestBody(strBody); } }
复制代码

 

方法二:  提供了一个非常简单的方法,可以直接替换body中的数据

 oSession.utilReplaceInRequest("1111", "2222");

转载于:https://www.cnblogs.com/Codenewbie/p/3357712.html

Guess you like

Origin blog.csdn.net/weixin_34023863/article/details/93448176