美文网首页
fiddler用法优化

fiddler用法优化

作者: 楚糖的糖 | 来源:发表于2021-09-18 11:22 被阅读0次
            if(oSession.uriContains("包含的URL字段")){
                FiddlerObject.log("===============================================");
                FiddlerObject.log("请求url:"+oSession.fullUrl);
                //FiddlerObject.log("请求方法:"+oSession.RequestMethod);
                FiddlerObject.log("请求头:"+oSession.RequestHeaders["api-version"]);
                //FiddlerObject.log("请求体数据:"+oSession.GetRequestBodyAsString());
                FiddlerObject.log("===============================================");
                }
            
            if (oSession.fullUrl.Contains("包含的URL字段")) {  
                var filename = "C:\\Users\\用户XX\\Desktop\\shunyi\\shunyitest.txt";
                var logContent = oSession.fullUrl + "\n";
                var version = oSession.RequestHeaders["api-version"] + "\n";
                var BodyAsString = oSession.GetRequestBodyAsString()+ "\n"+"===============================================\n";
                var sw : System.IO.StreamWriter;
                if (System.IO.File.Exists(filename)){  //是否有该文件夹  
                    sw = System.IO.File.AppendText(filename);   //有添加
                    sw.Write("请求url:"+logContent+"api-version:"+version+"Body:"+BodyAsString);
                }
                else{
                    sw = System.IO.File.CreateText(filename);  //没有创建
                    sw.Write("请求url:"+logContent+"api-version:"+version+"Body:"+BodyAsString);
                }
                sw.Close();
                sw.Dispose();
    
                }
    
    440129AF-3311-4e90-BC17-63FCB2D752B0.png

    响应优化,在【OnBeforeResponse】代码段加上如下内容

    
    
    if(oSession.fullUrl.Contains("jianshu.com")){  
            if(oSession.RequestMethod !="CONNECT"){
                if(oSession.PathAndQuery !=".js"){
                    var requestMethod = oSession.RequestMethod + "\n";
                    var filename = "D:\\apiReadme\\api-test.txt";
                    var logContent = oSession.fullUrl + "\n";
                    var version = oSession.RequestHeaders["api-version"] + "\n";
                    var BodyAsString = oSession.GetRequestBodyAsString()+ "\n";
                    var response = oSession.GetResponseBodyAsString()+ "\n"+"===============================================\n";       
                    
                    var sw : System.IO.StreamWriter;
                    if (System.IO.File.Exists(filename)){  //是否有该文件  
                        sw = System.IO.File.AppendText(filename);   //有则追加文本
                        sw.Write("请求方法:"+requestMethod+"请求url:"+logContent+"api-version:"+version+"Body:"+BodyAsString+"response:"+response);
                    }
                    else{
                        sw = System.IO.File.CreateText(filename);  //没有则创建
                        sw.Write("请求方法:"+requestMethod+"请求url:"+logContent+"api-version:"+version+"Body:"+BodyAsString+"response:"+response);
                    }
                    sw.Close();
                    sw.Dispose();
                }
            }
        }
    
    

    给别人接口偷懒的办法

    查看一个接口最需要的就是url,api-version,入参出参,每次找这些数据 ,还得挨个去复制,现在,直接去查看日志即可

        static function OnBeforeResponse(oSession: Session) {
            if (m_Hide304s && oSession.responseCode == 304) {
                oSession["ui-hide"] = "true";
            }
            if(oSession.uriContains("jianshu.com") && oSession.PathAndQuery !=".js" && oSession.GetRequestBodyAsString()!=""){
                FiddlerObject.log("===============================================");
                FiddlerObject.log("请求url:"+oSession.fullUrl);
                //FiddlerObject.log("请求方法:"+oSession.RequestMethod);
                FiddlerObject.log("api-version:"+oSession.RequestHeaders["api-version"]);
                FiddlerObject.log("请求体数据:"+oSession.GetRequestBodyAsString());
                FiddlerObject.log("响应:"+oSession.GetResponseBodyAsString());
                FiddlerObject.log("===============================================");
            }
        }
    

    相关文章

      网友评论

          本文标题:fiddler用法优化

          本文链接:https://www.haomeiwen.com/subject/upwegltx.html