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

Getting responsebody as base64 string.

2 Answers 1100 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 15 Nov 2015, 01:02 AM

Hi,
I am customising my fiddler script and was hoping to get the response body as a base64 string, is this possible?
I tried the following:
var bytes = Encoding.UTF8.GetBytes(oSession.GetResponseBodyAsString());
var base64 = Convert.ToBase64String(bytes);
FiddlerObject.log(base64);
However this did not work. I am probably missing something really obvious.
The response body is a PNG.
Many thanks
Pete

2 Answers, 1 is accepted

Sort by
0
Accepted
Eric Lawrence
Telerik team
answered on 16 Nov 2015, 05:52 PM
Hello, Peter--

You don't want to get a binary body as a string, as that's inherently lossy.

Instead, keep the bytes as bytes

        // Remove chunking & compression
oS.utilDecodeResponse(); 

        // Get raw bytes
        byte[] arrBody = oS.responseBodyBytes;

        // Convert to base64
        string sBase64 = Convert.ToBase64String(arrBody);


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
0
Peter
Top achievements
Rank 1
answered on 16 Nov 2015, 07:42 PM

Hi Eric,
That works brilliantly.
Many thanks for your help.
Pete

Tags
Fiddler Classic
Asked by
Peter
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Peter
Top achievements
Rank 1
Share this question
or