title: Displaying an image from HttpResponseMessage
body: <p>A .Net Core web app is using HttpClient to retrieve an image (I think?). If a browser using those end points, I think it will load an image. I can't check it as the end points require authorization through the header which cannot be done on browsers.</p>
  
  <pre><code>string endpoint = "somelink";
  HttpClient client = new HttpClient();
  client.BaseAddress = new Uri(endpoint);
  client.DefaultRequestHeaders.Add("Accept", "image/jpeg");
  client.DefaultRequestHeaders.Add("Authorization", "somekey");
  
  HttpResponseMessage response = await client.GetAsync(endpoint);
  Stream receiveStream = await response.Content.ReadAsStreamAsync();
  StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
  
  Console.WriteLine(response);
  Console.WriteLine(readStream.ReadToEnd());
  </code></pre>
  
  <p>I get the output as:</p>
  
  <p><a href="https://i.stack.imgur.com/FRpk3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FRpk3.png" alt="enter image description here"></a></p>
  
  <p>On the Server side, I am giving a byte array as content so it should be inside there somewhere. I am not sure how use this information to display the image.</p>
  
  <pre><code>[HttpGet, Route("some link")]
        public HttpResponseMessage GetQRCodeGeneratedForPackagedDrug(string id, bool returnSSLLink = false)
          {
              return GetQRCodeGenerated(id);
          }
  
      private HttpResponseMessage GetQRCodeGenerated(string drugId)
      {
          Stopwatch totalStopwatch = new Stopwatch();
          totalStopwatch.Start();
  
  
          try
          {
              QRCodeGenerator qrGenerator = new QRCodeGenerator();
              QRCodeData qrCodeData = qrGenerator.CreateQrCode(drugId, QRCodeGenerator.ECCLevel.Q);
              QRCode qrCode = new QRCode(qrCodeData);
              Bitmap qrCodeImageBitMap = qrCode.GetGraphic(20);
              ImageConverter converter = new ImageConverter();
              byte[] imgData = (byte[])converter.ConvertTo(qrCodeImageBitMap, typeof(byte[]));
              MemoryStream ms = new MemoryStream(imgData);
              HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
              response.Content = new StreamContent(ms);
              response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
              return this.Request.CreateResponse(System.Net.HttpStatusCode.OK, response);
          }
          catch (Exception ex)
          {
              throw new WebServicesException(ClaimsIdentityHelper.GetServiceCallID(), ex, callContext.CallID);
          }
          finally
          {
              totalStopwatch.Stop();
              Logger.LogResponseTracking(totalStopwatch.ElapsedMilliseconds, ClaimsIdentityHelper.GetServiceCallID(), this.GetType().ToString());
          }
      }
  </code></pre>