有些時候在測試環境和線上環境的不同,導致在線系統的js難易跟蹤調試特別是一些動態js腳本。fiddler這個工具給我減少了很多調試上的煩惱,尤其是強大的AutoResponder.
它可以抓取在線頁面保存到本地進行調試,這大大減少了在線調試的困難。
下面以http://www.fiddler2.com/fiddler2為例簡單描述一下操作步驟:
1、打開fiddler2,在瀏覽器中輸入http://www.fiddler2.com/fiddler2。在fiddler2可以看到請求記錄。
2、選擇需要調試的頁面,右鍵-Save-Response-Response body
3、修改需要調試的代碼段。
4、點擊fiddler AutoResponder Tab頁面,勾選Enable automatic responses,把http://www.fiddler2.com/fiddler2/這面拖拽到AutoResponder 列表中。
默認 Rule Editor為精匹配。在第二個文本框中選擇Find a file...,選擇本地保存后的文件。
5、保存規則后,重新請求http://www.fiddler2.com/fiddler2/,在看Fiddler websessions 列表新的請求Result 301,說明請求的是本地緩存的文件。
這樣就可以做我們想做的調試和修改了。
如果,你的請求是帶動態參數的化,可以使用正則表達式。
如:請求規則:Regex:(?insx)^http://.*gravatar.*$
Regex:(?insx)^http://.*WF_ID=WFDevFx_GCUSTOMIZE&ticket=.*$
*下面是詳細的過濾規則:
String Literals
Fiddler will match string literals (大小寫不敏感)
Rule |
Matches |
* |
http://www.example.com/Path1/query=example |
EXAMPLE |
http://www.example.com/Path1/query=example |
path1/ |
http://www.example.com/Path1/query=example |
query |
http://www.example.com/Path1/q=Query |
Exact Match(精確匹配)
Fiddler supports an exact, 大小寫敏感 match syntax for expressions which begin with exact:
Rule |
Matches |
EXACT:http://www.example.com/path |
http://www.example.com/path |
EXACT:http://www.example.com/path |
http://www.example.com/Path (No Match - mismatched case) |
EXACT:http://www.example.com/path |
http://www.example.com/path/q=Query (No Match - substring different) |
Regular Expressions(正則表達式)
Fiddler supports regular expression syntax for expressions which begin with regex:
Rule |
Matches |
regex:.* |
http://www.example.com/Path1/query=example |
regex:.*\.jpg |
http://www.example.com/Path1/query=foo.jpg&bar |
regex:.*\.jpg$ |
http://www.example.com/Path1/query=foo.jpg&bar (No Match - improper ending) |
regex:.*\.(jpg|gif|bmp)$ |
http://www.example.com/Path1/query=foo.bmp&bar (No Match - improper ending) |
regex:(?insx).*\.(jpg|gif|bmp)$ |
http://www.example.com/Path1/query=foo.bmp&bar (No Match - improper ending) |
抓取帶參數的請求並重定向:
請求:http://v.sdo.com/login/game_login.htm?isgamelogin=true&server=1&abb=csws&returnUrl=%2fcsws%2fplay.htm
在Rule Editor:表示為:
regex:(?insx)^http://v.sdo.com/login/game_login.htm\?(?<args>.*)$
*redir: http://www.cnblogs.com/peak-weng/archive/2012/01/19/2325855.html?${args}
如圖: