Please somebody help me

1 Answer 168 Views
Fiddler Classic
eric
Top achievements
Rank 1
eric asked on 20 Jan 2023, 09:33 AM

Hi everyone ! Can please somebody help me with a fiddler - script , to compile me a fiddler script from zero to replace 2 Json values on a website before-request ! i tryed with this : 

 

  static function OnBeforeRequest(oSession: Session)

 if(oSession.HostnameIs("mywebsite") && oSession.HTTPMethodIs("POST") && oSession.uriContains("/some.web/data/Entry/Validate"))           
    
        {  
  oSession.utilDecodeResponse();  
  var body = oSession.GetResponseBodyAsString();



 try {
                var dataJson = Fiddler.WebFormats.JSON.JsonDecode(body).JSONObject;
            
            
                var Co = (null);   // HERE I MUST REPLACE WITH (null)
                var Cap = MY-VALUE-HERE-LETTERS-AND-NUMBERS;  //EXAMPLE: FATH45786544565342U7  
            
                dataJson["Dispo"]["{}"]["Ben"]["Co"] = Co;
                dataJson["Dispo"]["{}"]["Ben"]["Cap"] = Cap;
          
            }
            catch(e) {
                FiddlerObject.log(e);
            }
        
                    
            body = Fiddler.WebFormats.JSON.JsonEncode(dataJson);       
          

}


///// i want to place the code in fiddler-script JS ////  please help me with a solution ! i am also ready to pay in btc for who want to help me ! thank you in advice !

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 23 Jan 2023, 07:03 AM

Hi Eric Mathew,

 

Once you get and update the JSON object, you need to convert it to bytes and set the modified bytes as HTTP Request body. Refer to the following SO thread for a basic example of how that would work:

https://stackoverflow.com/a/38461116/4936697

 static function OnBeforeRequest(oSession: Session) {

    if(oSession.HostnameIs("localhost")) {
        oSession["ui-backcolor"] = "lime";
        oSession["ui-bold"] = "Bold text here"

        // Convert the request body into a string
        var oBody = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);

        // Convert the text into a JSON object
        var j = Fiddler.WebFormats.JSON.JsonDecode(oBody);

        //Change the ConsistId value
        j.JSONObject["ConsistId"] = "A9C01636-0D8E-4C92-B09C-8413366E2D79";

        // Convert back to a byte array
        var modBytes = Fiddler.WebFormats.JSON.JsonEncode(j.JSONObject);

        // Convert json to bytes, storing the bytes in request body
        var mod = System.Text.Encoding.UTF8.GetBytes(modBytes);
        oSession.RequestBody = mod;

    }

 

Regards,
Nick Iliev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Fiddler Classic
Asked by
eric
Top achievements
Rank 1
Answers by
Nick Iliev
Telerik team
Share this question
or