public HttpResponseMessage GenerateQrCode(string url) { HttpResponseMessage responseMessage; try { var request = (HttpWebRequest)WebRequest.Create(WebConfigHelper.GetQrCodeGeneratorApiConfig() + url); request.Proxy = WebConfigHelper.GetWebProxy(); var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode.Equals(HttpStatusCode.OK)) { var byteImage = GetByteImage(response); var memoryStream = new MemoryStream(byteImage); responseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(memoryStream) }; responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); } else { responseMessage = new HttpResponseMessage(response.StatusCode) { Content = new StringContent(response.StatusDescription) }; } } catch (WebException e) { var statusCode = ((HttpWebResponse)e.Response)?.StatusCode ?? HttpStatusCode.NotFound; responseMessage = new HttpResponseMessage(statusCode) { Content = new StringContent(e.Message) }; } return(responseMessage); }