This is a migrated thread and some comments may be shown as answers.

Replace response textview?

7 Answers 1173 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
herson
Top achievements
Rank 1
Veteran
herson asked on 25 Mar 2021, 06:11 PM
I would like to know how to do this by scripting. Change a response text to another text automatically after the breakpoint. Example change eight:100% to height:5%. Thanks.

7 Answers, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 26 Mar 2021, 02:16 PM

Hello Herson,

 

You could use FiddlerScript and its events to modify headers and/or the body content of any request and response. In this documentation article, you will find multiple examples of using FiddlerScript and many of the build-in methods to modify HTTP requests and responses.

 

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/.

0
herson
Top achievements
Rank 1
Veteran
answered on 26 Mar 2021, 07:22 PM

Hi. Thanks.  I tried this but nothing happens. 

 

 if (oSession.uriContains("mysitefile.json") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){ oSession.utilDecodeResponse(); oSession.utilReplaceInResponse('eight:100%','eight:5%');}

0
Nick Iliev
Telerik team
answered on 29 Mar 2021, 10:32 AM

Hello Herson,

 

It is hard to pinpoint what exactly might be happening on your side. You could try to isolate the issue by providing the minimum code sample required to reproduce the case (alongside the used endpoint and details about the expected outcome).

You could also check if you are able to make a more cardinal change - for example try to entirely replace an Image or add new title to the very same response you are trying to modify (to test if you are able to hit the oSession conditions in the script).

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
herson
Top achievements
Rank 1
Veteran
answered on 29 Mar 2021, 11:07 AM
Hi thanks. Well, what I want to do is automatically change the response body automatically by script without using the autoresponder and bpafter tab ... modify the script replies from the file but not the headers.
0
Accepted
Nick Iliev
Telerik team
answered on 29 Mar 2021, 01:58 PM

Hеy Herson,

 

Have you tried using the onBeforeResponse event in FiddlerScript (see more here)? Your screenshot doesn't provide much information about the actual FiddlerScript code and the endpoints you might have used which is why we.ve asked for a code sample of the things you have tried so far.

Here is a very basic example, on how to change the HTML content in a received response from example.com

- Open FiddlerScript tab and make the response modification in onBeforeResponse event. In the example below, I am checking the session URL and if a specific header exists and then changing the H1 title to H3 with italic font.

    static function OnBeforeResponse(oSession: Session) {
        if (oSession.uriContains("example") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")) {
            oSession.utilDecodeResponse();
            oSession.utilReplaceInResponse('<h1>','<h3><em>');
            oSession.utilReplaceInResponse('</h1>','</em></h3>');   
        }

    }

- Use Save Script after applying the changes

- Open you browser (or use the Composer) and navigate to the example.com page.

As a result, you should now see a smaller title with italic style.

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
herson
Top achievements
Rank 1
Veteran
answered on 29 Mar 2021, 03:13 PM
Hello. Thank you very much for responding. It worked well on the example site. But if I try to do this on another site for example this: Sitelike Nothing happens. Trying to do the following example. Thank you for your help.
0
herson
Top achievements
Rank 1
Veteran
answered on 29 Mar 2021, 03:41 PM
[quote]Nick Iliev said:

Hеy Herson,

 

Have you tried using the onBeforeResponse event in FiddlerScript (see more here)? Your screenshot doesn't provide much information about the actual FiddlerScript code and the endpoints you might have used which is why we.ve asked for a code sample of the things you have tried so far.

Here is a very basic example, on how to change the HTML content in a received response from example.com

- Open FiddlerScript tab and make the response modification in onBeforeResponse event. In the example below, I am checking the session URL and if a specific header exists and then changing the H1 title to H3 with italic font.

 

    static function OnBeforeResponse(oSession: Session) {
        if (oSession.uriContains("example") && oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")) {
            oSession.utilDecodeResponse();
            oSession.utilReplaceInResponse('<h1>','<h3><em>');
            oSession.utilReplaceInResponse('</h1>','</em></h3>');   
        }

    }

 

- Use Save Script after applying the changes

- Open you browser (or use the Composer) and navigate to the example.com page.

As a result, you should now see a smaller title with italic style.

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

[/quote] thank you so much. It worked. I just forgot to change the Content-Type.
Tags
Fiddler Classic
Asked by
herson
Top achievements
Rank 1
Veteran
Answers by
Nick Iliev
Telerik team
herson
Top achievements
Rank 1
Veteran
Share this question
or