简书链接:fidder修改请求响应的2种方法
文章字数:84,阅读全文大约需要1分钟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
static function OnPeekAtResponseHeaders(oSession: Session) {
//FiddlerApplication.Log.LogFormat("Session {0}: Response header peek shows status is {1}", oSession.id, oSession.responseCode);
if (m_DisableCaching) {
oSession.oResponse.headers.Remove("Expires");
oSession.oResponse["Cache-Control"] = "no-cache";
}

if ((bpStatus>0) && (oSession.responseCode == bpStatus)) {
oSession["x-breakresponse"]="status";
oSession.bBufferResponse = true;
}

if ((null!=bpResponseURI) && oSession.uriContains(bpResponseURI)) {
oSession["x-breakresponse"]="uri";
oSession.bBufferResponse = true;
}
if (oSession.HostnameIs("lozn.free.idcfengye.com")){
// && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.bBufferResponse = true; //需要在返回头这里就设置buffer处理,否则,后续无法在onBeforeResponse中修改body(修改的动作不会阻塞原来的返回)
}

}

static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}

if (oSession.HostnameIs("lozn.free.idcfengye.com") && oSession.oResponse.headers.ExistsAndContains("Server","Kestrel")){
oSession.utilDecodeResponse();

oSession.utilReplaceInResponse("code","code\"=1,\"before");

oSession.utilReplaceInResponse('Content-Security-Policy','');

}
}

方法2

Fiddler-> Rules-> Automatic Breakpoints,点击【Before Responses】。