Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert to Stream from a Url

Tags:

c#

stream

I was trying to convert an Url to Stream but I am not sure whether I am right or wrong.

protected Stream GetStream(String gazouUrl) {     Stream rtn = null;     HttpWebRequest aRequest = (HttpWebRequest)WebRequest.Create(gazouUrl);     HttpWebResponse aResponse = (HttpWebResponse)aRequest.GetResponse();      using (StreamReader sReader = new StreamReader(aResponse.GetResponseStream(), System.Text.Encoding.Default))     {         rtn = sReader.BaseStream;     }     return rtn; } 

Am I on the right track?

like image 818
Nazmul Avatar asked Jun 24 '10 02:06

Nazmul


1 Answers

I ended up doing a smaller version and using WebClient instead the old Http Request code:

private static Stream GetStreamFromUrl(string url) {     byte[] imageData = null;      using (var wc = new System.Net.WebClient())         imageData = wc.DownloadData(url);      return new MemoryStream(imageData); } 
like image 89
balexandre Avatar answered Sep 21 '22 13:09

balexandre