码迷,mamicode.com
首页 > 其他好文 > 详细

如何在Fiddler Script中自定义修改请求参数

时间:2019-03-22 12:59:03      阅读:1035      评论:0      收藏:0      [点我收藏+]

标签:https   contains   for   .com   article   script   字符串   函数   ||   

-更改RequestHeaders中的内容

//根据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/", "/");   
    }
}

 

-更改ResponseBody中JSON数据

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:

https://blog.csdn.net/qq_37299249/article/details/70558861

https://www.cnblogs.com/yanjc/p/6716733.html

如何在Fiddler Script中自定义修改请求参数

标签:https   contains   for   .com   article   script   字符串   函数   ||   

原文地址:https://www.cnblogs.com/phpdragon/p/10577556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!