Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am supposed to download(response stream) different formats of a file from a URL and let the user download the same from my asp.net web api.

HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse();
var response = new HttpResponseMessage(HttpStatusCode.OK);

  if (httpResponse != null)
  {
      using (var responseApi = (HttpWebResponse)httpResponse)
      {
          using (var reader = new StreamReader(responseApi.GetResponseStream()))
          {
              var objText = reader.ReadToEnd();
              response.Content = new StringContent(objText, Encoding.UTF8, "application/json");
          }
      }
  }


Since FileStreamResult cannot be used in web api, i tried converting the httpwebresponse to HttpResponseMessage.

What I have tried:

Converting httpWebResponse to HttpResponseMessage
C#
<pre>var responseApi = (HttpWebResponse)httpResponse)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900