get image with httpwebrequest to stream to byte array to base64

G

Guest

I was make an function which reads file from windows path and read that image
with bytereader I able to make it,
Then I try to get that image from httpwebrequest but I get convert'ing
problems
stream to string to byte[] to base64?

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(imagelink);
HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse();

Stream mystream=myResponse.GetResponseStream();
StreamReader mystreamReader=new StreamReader(mystream);

string result=mystreamReader.ReadToEnd();

byte[] mybytes;
mybytes=new System.Text.ASCIIEncoding().GetBytes(result);

returnstring+=Convert.ToBase64String(mybytes);

Thanks for your help.
 
J

Joerg Jooss

Esref said:
I was make an function which reads file from windows path and read
that image with bytereader I able to make it,
Then I try to get that image from httpwebrequest but I get convert'ing
problems
stream to string to byte[] to base64?

HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(imagelink); HttpWebResponse
myResponse=(HttpWebResponse)myRequest.GetResponse();

Stream mystream=myResponse.GetResponseStream();
StreamReader mystreamReader=new StreamReader(mystream);

string result=mystreamReader.ReadToEnd();

byte[] mybytes;
mybytes=new System.Text.ASCIIEncoding().GetBytes(result);

returnstring+=Convert.ToBase64String(mybytes);

Don't use TextReaders to read binary data! Simply consume the
ResponseStream.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top