title: Get picture from HttpClient
body: <p>I need help retrieving a picture from a web service. It's a GET request.</p>
  
  <p>At the moment I am retrieving a response and I am able to convert it to a byte array, which is what I am going for, but the byte array crashes the app, so I don't think the content is set right.</p>
  
  <p>I have tried to set the response content with:</p>
  
  <pre><code>response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename };     
  </code></pre>
  
  <p>Even though my guess is that it is set incorrectly, or it is up in the requestHeader it is set wrong.</p>
  
  <p>Any ideas?</p>
  
  <pre><code>using (var client = new HttpClient())
  {
      client.BaseAddress = new Uri(baseurl.uri);
      client.DefaultRequestHeaders.Add("x-access-token", sessionToken);
      client.DefaultRequestHeaders
            .Accept
            .Add(new MediaTypeWithQualityHeaderValue("image/jpeg")
              );
  
      HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "");
      try
      {
          Task&lt;HttpResponseMessage&gt; getResponse = client.SendAsync(request);
          HttpResponseMessage response = new HttpResponseMessage();
          response = await getResponse;           
           //1. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename };
          //2. response.Content.Headers.ContentType =
  
         //new MediaTypeHeaderValue("image/jpeg");//("application/octet-stream");
  
  
          byte[] mybytearray = null;
          if (response.IsSuccessStatusCode)
          {
          //3.
              mybytearray = response.Content.ReadAsByteArrayAsync().Result;
          }
  
          var responseJsonString = await response.Content.ReadAsStringAsync();
          System.Diagnostics.Debug.WriteLine(responseJsonString);
          System.Diagnostics.Debug.WriteLine("GetReportImage ReponseCode: " + response.StatusCode);
          return mybytearray;//{byte[5893197]}
      }
      catch (Exception ex)
      {
          string message = ex.Message;
          return null;
      }
  }
  </code></pre>