Getting responsebody as base64 string.

3 posts, 1 answers
  1. Peter
    Peter avatar
    2 posts
    Member since:
    Nov 2015

    Posted 14 Nov 2015 Link to this post

    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. Answer
    Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 16 Nov 2015 Link to this post

    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
  3. Peter
    Peter avatar
    2 posts
    Member since:
    Nov 2015

    Posted 16 Nov 2015 Link to this post

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

Back to Top