title: The input is not a valid Base-64 string as it contains a non-base 64 character
body: <p>I have a REST service that reads a file and sends it to another console application after converting it to Byte array and then to Base64 string. This part works, but when the same stream is received at the application, it gets manipulated and is no longer a valid Base64 string. Some junk characters are getting introduced into the stream.</p>
  
  <p>The exception received when converting the stream back to Byte is </p>
  
  <blockquote>
    <p>The input is not a valid Base-64 string as it contains a non-base 64
    character, more than two padding characters, or a non-white space
    character among the padding characters</p>
  </blockquote>
  
  <p><strong>At Service:</strong></p>
  
  <pre><code>[WebGet(UriTemplate = "ReadFile/Convert", ResponseFormat = WebMessageFormat.Json)]  
  public string ExportToExcel()
    {
        string filetoexport = "D:\\SomeFile.xls";
        byte[] data = File.ReadAllBytes(filetoexport);
        var s = Convert.ToBase64String(data);
        return s;
    }
  </code></pre>
  
  <p><strong>At Application:</strong></p>
  
  <pre><code>       var client = new RestClient("http://localhost:56877/User/");
         var request = new RestRequest("ReadFile/Convert", RestSharp.Method.GET);
         request.AddHeader("Accept", "application/Json");
         request.AddHeader("Content-Type", "application/Json");
         request.OnBeforeDeserialization = resp =&gt; {resp.ContentType =    "application/Json";};
         var result = client.Execute(request);
         byte[] d = Convert.FromBase64String(result.Content); 
  </code></pre>