Fiddler packet capture-automatically save session

background

Capture APP packets and automatically save them to prepare for subsequent work.

The expected process is: Use appium to simulate user trigger requests -> Use fiddler to grab requests -> Verify whether the request meets expectations. 
Fiddler's Customize Rules function supports users to add scripts (Java Script) to implement custom functions. 

Use Fiddler to capture mobile requests. Check it out on Baidu. There is a lot of information and it is very complete.

Step 1: Start fiddler and open Fiddler ScriptEditor

Click “Rules–》Customize Rules…” in the top workbar, as shown in the figure below:

 

Step 2: ctrl+f to find the OnBeforeRequest function

Add the following code after this function:

//Filter irrelevant requests and only focus on specific requests 
        if (oSession.fullUrl.Contains("Fill in the domain name to be captured")) { 
            var fso;
            var file; 
            fso = new ActiveXObject("Scripting.FileSystemObject");
            //File Save path, you can customize 
            file = fso.OpenTextFile("Fill in the address to save the TXT file",8,true, true); 
            file.writeLine("Request url: " + oSession.url); 
            file.writeLine("Request header: " + "\n" + oSession.oRequest.headers); 
            file.writeLine("Request body: " + oSession.GetRequestBodyAsString()); 
            file.writeLine("\n"); 
            file.close(); 

        }

Then look for the OnBeforeResponse function and add the following code at the end of the function:

        //Filter irrelevant requests and only focus on specific requests 
        if (oSession.fullUrl.Contains("Fill in the domain name to be captured")) { 
            oSession.utilDecodeResponse();
            //Eliminate the possibility of garbled characters in saved requests 
            var fso; 
            var file; 
            fso = new ActiveXObject("Scripting.FileSystemObject"); 
            //The file saving path can be customized 
            file = fso.OpenTextFile("Fill in the save TXT file address",8,true, true); 
            file.writeLine("Response code: " + oSession.responseCode); 
            file.writeLine("Response body: " + oSession.GetResponseBodyAsString()); 
            file.writeLine("\n"); 
            file.close(); 

        }

    OK, after restarting fiddler, you can start capturing packets and save them automatically.
 

Guess you like

Origin blog.csdn.net/llq_the7/article/details/103789110