您的位置:首页 > 理论基础 > 计算机网络

fiddler录制http请求

2015-07-24 15:41 513 查看
为了只保留操作过程中的关键请求数据,我们需要自定义fiddler的过滤项。

完整的录制步骤如下:

打开fiddler2,此时后台会启动一个代理服务器。此后所有的http请求都会经过此代理服务器进行请求转发。

配置fiddler2过滤项。

1:首先需要只保留fiddler对浏览器请求的捕捉。点击左下角处的"All processes"变成"Web Browers"即可。这样fiddler就只捕捉IE或Firefox的请求

2:指定默认的Rules。在fiddler的菜单栏中选择"Rules",弹出下拉列表后,选择以下三项:"Hide Image Requests","Remove All Encodings","Hide 304s".

自定义过滤规则。由于目前的平台4.0系统中存在有大量的循环或显示用的请求,因此还需要自定义过滤规则。

3:选择"Rules"--->"Customize Rules",在弹出的文本文件中进行修改和补充后,自定义规则即时生效。或者使用Rules插件进行修改.

在该文件中找到static function OnBeforeRequest(oSession: Session),OnBeforeResponse方法,增加相应的过滤规则,就会相应的过滤请求。

以下为OnBeforeRequest中增加的过滤条件.附件为一修改后的脚本CustomRules.js

该文件位于C:\Documents and Settings\username\My Documents\Fiddler2\Scripts

//过滤请求不显示到界面上.

if(oSession.HTTPMethodIs("GET")){

oSession["ui-hide"] = "true";

} else{

if (oSession.uriContains("BootAndPtStatus.do")){

oSession["ui-hide"] = "true";

}

if (oSession.uriContains("Alarmlog.do")){

oSession["ui-hide"] = "true";

}

if (oSession.uriContains("SystemRun.do")){

oSession["ui-hide"] = "true";

}

}保存脚本。在左侧的请求序列中,选择需要保存的请求数据后,点击右键在弹出的界面中,选择"Save "->"Sessions"->"As Text".这样选中的请求就会以文本形式保存。

下面为保存的已录制脚本数据.

该脚本中包含三个步骤的操作:登陆->强制登陆-->登出

POST /login.dof?action=userLogin HTTP/1.1

Accept: */*

Accept-Language: zh-cn

Referer: http://192.168.19.2:8080/login.html
x-requested-with: XMLHttpRequest

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; QQDownload 1.7; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

Host: 192.168.19.2:8080

Content-Length: 30

Connection: Keep-Alive

Pragma: no-cache

Cookie: JSESSIONID=C404BA0368933D32FA08A5EF1BAE2D49

username=admin&password=123456

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Type: text/json;charset=utf-8

Date: Mon, 16 Mar 2009 02:32:47 GMT

Content-Length: 132

{"success":false,"errors":{"exception":""},"isgrab":"[admin]正在被IP=[192.168.12.154]的用户使用中,是否抢占登录?"}

------------------------------------------------------------------

POST /login.force?action=userLogin HTTP/1.1

Accept: */*

Accept-Language: zh-cn

Referer: http://192.168.19.2:8080/login.html
x-requested-with: XMLHttpRequest

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; QQDownload 1.7; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

Host: 192.168.19.2:8080

Content-Length: 30

Connection: Keep-Alive

Pragma: no-cache

Cookie: JSESSIONID=C404BA0368933D32FA08A5EF1BAE2D49

username=admin&password=123456

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Set-Cookie: JSESSIONID=FD32F2962420B7BA72A1BAD3ACBEB616; Path=/

Content-Type: text/json;charset=utf-8

Date: Mon, 16 Mar 2009 02:32:50 GMT

Content-Length: 44

{"success":true,"message":"操作成功!"}

------------------------------------------------------------------

POST /logout.dof?action=logout HTTP/1.1

Accept: */*

Accept-Language: zh-cn

Referer: http://192.168.19.2:8080/index.html
x-requested-with: XMLHttpRequest

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; QQDownload 1.7; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)

Host: 192.168.19.2:8080

Content-Length: 0

Connection: Keep-Alive

Pragma: no-cache

Cookie: JSESSIONID=FD32F2962420B7BA72A1BAD3ACBEB616

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Type: text/json;charset=utf-8

Date: Mon, 16 Mar 2009 02:33:00 GMT

Content-Length: 59

{"success":false,"errors":{"sessionout":true,"outinfo":""}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: