title: C# Get Byte Array from HTTPResposeMessage
body: <p>I have an API that returns a PDF file as a byte array:</p>
  <pre><code>HttpResponseMessage fileResponse = new HttpResponseMessage
  {
      Content = new ByteArrayContent(report) //here the byte array is &gt;80000 in length
  };
  fileResponse.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(&quot;application/pdf&quot;);
  return fileResponse;
  </code></pre>
  <p>On the client, I have:</p>
  <pre><code>HttpResponseMessage result = null;
  using (HttpClient client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
  {
      result = await client.GetAsync(getFileURL);
  }
  Byte[] bytes = response.Content.ReadAsByteArrayAsync().Result;
  </code></pre>
  <p>This code worked until an upgrade to .Net 5.</p>
  <p>Now bytes is only &lt;350 in length. I have tried converting it from a base64 string as I have read in other solutions, but that throws an error saying it is not a valid base64 string:</p>
  <pre><code>string base = response.Content.ReadAsStringAsync().Result.Replace(&quot;\&quot;&quot;, string.Empty);
  byte[] byte = Convert.FromBase64String(base);
  </code></pre>
  <p>Here's what base looks like after the replace, which the next line says is not a valid base64 string. Looks like json but no byte array:</p>
  <pre><code>{version:{major:1,minor:1,build:-1,revision:-1,majorRevision:-1,minorRevision:-1},content:{headers:[{key:Content-Type,value:[application/pdf]}]},statusCode:200,reasonPhrase:OK,headers:[],trailingHeaders:[],requestMessage:null,isSuccessStatusCode:true}
  </code></pre>
  <p>So any ideas on how to get the byte array out the response?</p>