Get image file from a website through proxy?

Jan 26 2004 12:34 AM
hi all, I know that I can get an HTML page from a web server through proxy, but I can't get an image file from that web server. Could someone tell me how to do that? Below is my 2 snippets of code that all have errors: //1, using WebRequest: image file to be saved is wrong format, can not view WebRequest req = WebRequest.Create("http://www.google.com/images/logo.gif"); WebProxy myProxy = new WebProxy("http://10.23.23.25:8080", true); req.Proxy = myProxy; WebResponse result = req.GetResponse(); Stream ReceiveStream = result.GetResponseStream(); StreamReader sr = new StreamReader( ReceiveStream ); resultstring = sr.ReadToEnd(); FileStream myFileStream = File.Create("c:\\logo.gif"); StreamWriter writer = new StreamWriter(myFileStream); writer.Write(resultstring); writer.Close(); //2, using WebClient: can not go through proxy WebClient myWebClient = new WebClient(); myWebClient.DownloadFile("http://www.google.com/images/logo.gif","c:\\logo.gif"); Any help will be very appreciated, Thanks Khanh