揰掵佲 发表于 2023-3-2 07:37:43

[转]通过fiddlerscript把抓包内容转发到自己接口上

打开fiddlerscript选项   切换 or 下拉到 OnBeforeResponse   所有请求返回后都会经过这个函数在这函数里设置将数据转到到我们的远程接口上保存...
命令我大概都写了备注   基本都能看懂把...

static function OnBeforeResponse(oSession: Session) {
      if (m_Hide304s && oSession.responseCode == 304) {
            oSession["ui-hide"] = "true";
      }
      // 方法内追加的演示代码
      //var ci_host = "http://localhost:6667/fiddle";

      
      //判断链接的地址包含的链接内容部分,如果匹配到,就进入if 代码块内
      if (oSession.uriContains("/api/v1/sams/goods-portal/grouping/list")) {
            //标记匹配到的uri显示的颜色
            //oSession["ui-color"] = "maroon";

            //消除保存的请求可能存在乱码的情况
            oSession.utilDecodeRequest();
            //获取post请求的请求内容块(request body)
            
            var responseString = oSession.GetResponseBodyAsString();
            var postdat = responseString ;
            
            var requestString = oSession.GetRequestBodyAsString ();
            
            //var str='{}';//构造自己的JSON http请求的信息及返回的结果
            var data = Fiddler.WebFormats.JSON.JsonDecode(requestString);
            var secondCategoryId =data.JSONObject["secondCategoryId"];
            
            //FiddlerObject.log('secondCategoryId:' + secondCategoryId);
            //var jsonValue = window.JSON.parse(requestString);
            //var secondCategoryId = jsonValue.secondCategoryId;
            
            var ci_host = "http://master.xxxxx.com/extra/fiddler/index.php?malltype=3&taskname=rpush&secondCategoryId=" + secondCategoryId;
            
            //因为post请求头的 Content-type : application/x-www-form-urlencoded
            //所以 请求内容块中的格式是: app_id=100&app_key=200&product_id=1

            //待获取的请求参数名称
            //var variable1 = 'product_id';
            //声明存放产品id参数值的变量
            //var product_id = "";
            //根据 & 分割请求内容的参数
/*            var vars = requestString.split('&');
            for (var i = 0; i < vars.length; i++) {
                //根据 = 分割单个键值对,
                var pair = vars.split('=');
                //匹配参数名称(键)
                if (decodeURIComponent(pair) == variable1) {
                  //如匹配到,将匹配到的参数值赋值到预先定义的变量:product_id
                  product_id =decodeURIComponent(pair);
                }
            }
*/
      
            //if(product_id != ""){


                //请求本地的一个连接来记录监听到的产品id,做相应的处理
                var _xhr2 = new ActiveXObject("Microsoft.XMLHTTP");
                var singleshare_url = ci_host;
                _xhr2.onreadystatechange = function() {};
                _xhr2.open("POST", singleshare_url, false);
                //_xhr2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
                _xhr2.send(postdat);
               
                //写日志,可在 fiddler软件右边的窗口的 "日志"选项卡中看到日志输出_xhr2.responseTwxt()
                FiddlerObject.log('product_id:' + _xhr2.responseText);
                //UI.lvSessions.SelectedItems.Clear();
               
            //}
      }
      
      
    }
页: [1]
查看完整版本: [转]通过fiddlerscript把抓包内容转发到自己接口上