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

FIddlerCore - Manipulating Response to Web Browser not Working

2 Answers 383 Views
Windows
This is a migrated thread and some comments may be shown as answers.
kris
Top achievements
Rank 1
kris asked on 01 Nov 2015, 09:19 PM

Thanks for FiddlerCore and the quick responses to questions on this forum.
I'm trying to intercept a webpage response, change some html, and have it display my change in the browser:

private void FiddlerApplication_BeforeResponse(Session oSession)

{

oSession.bBufferResponse = true;

oSession.utilDecodeResponse();

 

oSession.utilReplaceInResponse("TEXT-TO-REPLACE", "NEW-TEXT");

}

I should note that I'm using Windows 10, which I'm not sure if it makes any difference.  I know that the oSession's ResponseBody text is updated when I use this code, however it seems like it doesn't get passed on to the browser from this point.  Am I missing something?  I've even tried utilSetResponseBody(updatedBodyText), however this doesn't seem to update the returned page either.  Any thoughts or help would be greatly appreciated.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
 

 

2 Answers, 1 is accepted

Sort by
0
kris
Top achievements
Rank 1
answered on 01 Nov 2015, 09:47 PM
By the way, sorry for the yucky post -- had no idea it would show up like that.  Should have looked at 'Formatting options.'  Anyways, I ended up finding the solution to my problem from stumbling upon another forum post.  It turns out that I was setting oSession.bBufferResponse = true in the wrong event handler (BeforeResponse).  I set bBufferResponse in the BeforeRuquest event and everything works as expected. 
0
Eric Lawrence
Telerik team
answered on 02 Nov 2015, 05:27 PM
Hi, Kris--

Yup, changing it inside BeforeRequest works.

One helpful thing you can do is prototype your changes in Fiddler itself (using FiddlerScript) before moving to FiddlerCore. 

If you open your FiddlerScript, you'll see the following note:

    //
    // If a given session has response streaming enabled, then the OnBeforeResponse function 
    // is actually called AFTER the response was returned to the client.
    //
    // In contrast, this OnPeekAtResponseHeaders function is called before the response headers are 
    // sent to the client (and before the body is read from the server).  Hence this is an opportune time 
    // to disable streaming (oS.bBufferResponse = true) if there is something in the response headers 
    // which suggests that tampering with the response body is necessary.

    // 
    // Note: oSession.responseBodyBytes is not available within this function!
    //

In FiddlerCore, the last possible moment to change bBufferResponse is the ResponseHeadersAvailable event.

Regards,
Eric Lawrence
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Windows
Asked by
kris
Top achievements
Rank 1
Answers by
kris
Top achievements
Rank 1
Eric Lawrence
Telerik team
Share this question
or