Fiddler是一個http協議調試代理工具,方便進行http請求的攔截處理、改寫請求、返回值等。html
在Rules菜單下:
web
這次更改請求 頭 ,so go to OnBeforeRequestjson
或者api
//根據host判斷 if(oSession.host=="www.baidu.com"){ oSession.RequestHeaders.Remove("User-Agent"); oSession.RequestHeaders.Add("User-Agent","Dalvik/2.1.0 (Linux; U; Android 9.0.1; onePlus666 Build/MOB31K)"); }
//請求攔截 var isTelecomAuth: boolean = false; if(oSession.host == 'www.xxxxxx.com' && oSession.url.Contains("/api/")){ isTelecomAuth = oSession.url.Contains("/api/web/telecom/getTel"); isTelecomAuth = isTelecomAuth || oSession.url.Contains("/api/web/telecom/addAuthRecord"); //若是不是運營商授信,進行攔截 if(!isTelecomAuth){ oSession.host = 'api.xxxxx.com'; oSession.url = oSession.url.Replace("/api/", "/"); } }
Go->go to OnBeforeResponse定位到OnBeforeResponse函數,在末尾添加:函數
if(oSession.host == 'www.xxxx.com' && oSession.url.Contains("/api/xxx")){ //更改後的JSON數據 var mylogin='{"uids":[200005445],"card_type":1,"cmd":"2124525","token":"26fed74802233c112bb7e9fcb97a11ac"}'; var requestJson=Fiddler.WebFormats.JSON.JsonDecode(mylogin); var reJsonDes=Fiddler.WebFormats.JSON.JsonEncode(requestJson.JSONObject); oSession.utilSetRequestBody(reJsonDes); //替換字符串 //var strBody = oSession.GetRequestBodyAsString(); //oSession.utilSetRequestBody(strBody.Replace("com.jyblife.risk.profile.service.AuthStateService","com.jyblife.risk.profile.service.AuthStateService")); //打印修改後的內容 //MessageBox.Show(oSession.GetRequestBodyAsString()); }
這裏沒有對原JSON數據修改,而直接定義了新的JSON數據替換。工具
PS:ui
https://blog.csdn.net/qq_37299249/article/details/70558861url
https://www.cnblogs.com/yanjc/p/6716733.htmlspa