How to modify the response in FiddlerCore?

545 views
Skip to first unread message

Naruto Lee

unread,
Jan 10, 2018, 12:45:08 AM1/10/18
to Fiddler
Hi,guys,I want using FiddlerCore modify the Response in selenium,but it does not take effect,I needs inject jscript into the response pages,beacuse i need to achieve the drag verification code. these Code is form C#,that in FiddlerScript is Working,but in C# is not Working..
The Development environment is visual Studio 2015 + FiddlerCore2 + .net4.5.2

Reference from:https://stackoverflow.com/questions/48165807/how-to-modify-the-response-in-fiddlercore
FiddlerApplication.Startup(8887, FiddlerCoreStartupFlags.Default); FiddlerApplication.BeforeResponse +=new SessionStateHandler(delegate (Session oSession) { oSession.bBufferResponse = true; oSession.utilDecodeResponse(); var Body = oSession.GetResponseBodyAsString(); Body = Regex.Replace(Body, @"SomeText", "12345",RegexOptions.Singleline); oSession.utilSetResponseBody(Body); });


Eric Lawrence

unread,
Jan 10, 2018, 12:30:27 PM1/10/18
to Fiddler
Setting oSession.bBufferResponse = true; inside the BeforeResponse handler is too late... the response has already been leaked.

Note to FiddlerCore Developers:When the bBufferResponse property on a session is set to false, that session's response is streamed to the client as it is being read from the server. As a consequence, the client has already received the response before the BeforeResponse event has fired. In contrast, if that property is set to true, that Session's response will be buffered until complete, then the BeforeResponse event fires, then the response is sent to the client. The last event guaranteed to fire before the client starts getting response bytes is FiddlerApplication.ResponseHeadersAvailableYou can use that event handler to set the bBufferResponse property if you need to modify the response bytes before the client receives them.


Eric Lawrence

unread,
Jan 10, 2018, 12:34:28 PM1/10/18
to Fiddler
The FiddlerBook provides a good code sample that conditionally buffers the response only for the appropriate types:

ResponseHeadersAvailable Event 
This event fires when FiddlerCore has read the complete set of response headers from the server. It provides the opportunity to set the Session’s bBufferResponse property based on the contents of the headers: 

 FiddlerApplication.ResponseHeadersAvailable += delegate(Session oS) { 
   // Disable streaming for HTML responses on a target server so that 
   // we can modify those responses in the BeforeResponse handler 
   if (oS.HostnameIs("example.com") && oS.oResponse.MIMEType.Contains("text/html")) { 
       oS.bBufferResponse = true; 
   } 
    // Or, enable streaming for responses that need to stream  
   string sContentType = oS.oResponse.headers["Content-Type"]; 
   if (sContentType.OICStartsWithAny(
       "text/event-stream", "multipart/x-mixed-replace",
       "video/", "audio/", "application/x-mms-framed")) {
     oS.bBufferResponse = false; 
   } 
 }; 
Reply all
Reply to author
Forward
0 new messages