Replace response body

1 Answer 1764 Views
Fiddler Classic
D
Top achievements
Rank 1
D asked on 12 Oct 2022, 12:49 PM

Hi,

I use Fiddler Classic as a proxy between client and server. I tried to replace the entire response body for a request.


static function OnBeforeResponse(oSession: Session) {
...
var body = '<?xml version="1.0" encoding="UTF-8"?><Test/>';
oSession.ResponseBody = System.Text.Encoding.UTF8.GetBytes(body);
oSession.oResponse['Content-Length'] = body.Length;
oSession.utilSetResponseBody(body);
...
}

Unfortunately this does not work. Fiddler show the changed content, but body was send to server completely unchanged. Any suggestion?

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 12 Oct 2022, 01:28 PM

Hi D Florian,

 

The described behavior is expected as the server has already received the request.

https://docs.telerik.com/fiddler/knowledge-base/fiddlerscript/modifyrequestorresponse#modifying-a-request-or-response

 Note:

It is not possible to access the response objects inside OnBeforeRequest as they have not yet been created.
It is possible to use objects from the request inside OnBeforeResponse; however, any changes you make to those objects will not be seen by the server, as it has already received the request.

 

 

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.

D
Top achievements
Rank 1
commented on 13 Oct 2022, 06:30 AM

Thank you Nick for clarification,

Is there absolutely no way to modify response body before it is send?

Regards
Florian

Nick Iliev
Telerik team
commented on 13 Oct 2022, 06:45 AM

The HTTP response is received, not sent (see basic illustration on how that Fiddler works as MITM). What Fiddler allows you to do by modifying a response is to mock server behavior. If you wish actually to receive a different server response, then you should change the request that the server receives.
D
Top achievements
Rank 1
commented on 13 Oct 2022, 08:26 AM | edited

Hi Nick,

may be I did not understand. According to this documentation every traffic is routed through Fidller.


The Fiddler Everywhere proxy forwards the response to the client application.

Any active Fiddler Everywhere rules (modifying the responses) are applied here.


Our goals is to capture some traffic data to debug what is send back and forth using Fiddler. Client is connecting to our DSN. Through Cloudflared the traffic is then routed to a local machine to port 8888 (Filddler). Then we modify URLS using rules and then Proxy is sending the traffic to the real server residing somewhere in the internet. Input request from client can easily be modified, but response we get back from server cannot be modified or replaced. Basically we only need to change the host names and URLs send back in server response to point to our DSN to stay involved in traffic capturing. From my understanding a Proxy should be able to modify any traffic going through. Is my understand so wrong? I already tried to stop streaming, but that did also not help.


static function OnBeforeRequest(oSession: Session) {
...
oSession.bBufferResponse = false;
...
}

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