- 拦截请求入参(通过修改
send
方法修改)
| class XMLHttpRequestInter extends window.XMLHttpRequest { |
| constructor(...args) { |
| super(...args); |
| } |
| send(...params) { |
| const yourParams = [] |
| |
| super.send(...yourParams); |
| } |
| } |
| window.XMLHttpRequest = XMLHttpRequestInter; |
- 拦截请求回来的数据
| class XMLHttpRequestInter extends window.XMLHttpRequest { |
| constructor(...args) { |
| super(...args); |
| } |
| open(...params) { |
| |
| const url = params[1]; |
| |
| ... |
| |
| if (条件 === true) { |
| const originalOnReadyStateChange = super.onreadystatechange; |
| super.onreadystatechange = () => { |
| if (this.readyState === 4 && this.status === 200) { |
| |
| const res = super.response; |
| |
| const yourRes = ...; |
| this.response = yourRes; |
| } |
| originalOnReadyStateChange.call(this); |
| }; |
| } |
| return super.open(...params); |
| } |
| } |
| window.XMLHttpRequest = XMLHttpRequestInter; |
方法名 |
描述 |
示例 |
FiddlerObject.alert(ebody) |
fiddler script alert 方法 |
:---------------------------------- |
-
OnBeforeRequest(oSession: Session)
方法名 |
描述 |
示例 |
GetRequestBodyAsString |
获取字符串形式的请求体 |
'[{"actionType":"initUser"}]' |
Fiddler.WebFormats.JSON.JsonDecode(GetRequestBodyAsString()) |
将获取字符串形式的请求体转化为 JSON |
[{"actionType":"initUser"}] |
| function OnBeforeRequest(oSession) { |
| const rqbody = oSession.GetRequestBodyAsString(); |
| if (rqbody.Contains('your string')) { |
| |
| const rqbodyJSON = Fiddler.WebFormats.JSON.JsonDecode(rqbody); |
| |
| rqbodyJSON.JSONObject["params"]["loginName"] = "new name"; |
| |
| const rqbodyChanged = Fiddler.WebFormats.JSON.JsonEncode(rqbodyJSON.JSONObject); |
| |
| oSession.utilSetRequestBody(rqbodyChanged); |
| } |
| } |
-
OnBeforeResponse(oSession: Session)
方法名 |
描述 |
示例 |
GetResponseBodyAsString |
获取字符串形式的响应体 |
'[{"actionType":"initUser"}]' |
Fiddler.WebFormats.JSON.JsonDecode(GetResponseBodyAsString()) |
将获取字符串形式的响应体转化为 JSON |
[{"actionType":"initUser"}] |
| function OnBeforeResponse(oSession) { |
| const rsbody = oSession.GetResponseBodyAsString(); |
| if (rsbody.Contains('your string')) { |
| |
| const rsbodyJSON = Fiddler.WebFormats.JSON.JsonDecode(rsbody); |
| |
| rsbodyJSON.JSONObject["proName"] = "new name"; |
| |
| const rsbodyChanged = Fiddler.WebFormats.JSON.JsonEncode(rsbodyJSON.JSONObject); |
| |
| oSession.utilSetResponseBody(rsbodyChanged); |
| } |
| } |
- 查看拦截界面:
http://local.whistlejs.com/
- 通过配置 host 进行抓包
- 请求体只能获取 16k
- 参考地址:
http://wproxy.org/whistle/