Getting responsebody as base64 string.

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

    Posted 14 Nov 2015 Link to this post

    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);
    However this did not work. I am probably missing something really obvious.
    The response body is a PNG.
    Many thanks

  2. Answer
    Eric Lawrence
    Eric Lawrence avatar
    832 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

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

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

    Eric Lawrence
    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.

  4. Predrag
    Predrag avatar
    1 posts
    Member since:
    May 2018

    Posted 15 May in reply to Peter Link to this post

Back to Top