Hey guys,
Ive been having a problem downloading files through a proxy server. it worked fine while i was downloading small test files (zip files to be exact < 5kb) but when i use actual files, they are always corrupt on the client side, but when you open the zip file there are never more than 2 files present and they are corrupt as well. any help would be greatly appreciated.
Thanks,
here is a before and after screen shot of the zip files, if that helps, and the following is a code snippit.
public void BeginDownload(){
WebProxy proxy = new WebProxy(ServPath, true);
proxy.Credentials = new NetworkCredential(UserName, Pass);
WebRequest request = WebRequest.Create(ServPath + FileName);
request.Proxy = proxy;
// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
FileStream writeStream = new FileStream(DownloadPath + FileName, FileMode.Create, FileAccess.Write);
ReadWriteStream(stream, writeStream, response
.ContentLength);
response
.Close();
}
private void ReadWriteStream(Stream readStream, Stream writeStream, long lLength){
int Length = Convert.ToInt32(lLength);
Byte[] buffer = new Byte[Length + (100 - Length%100) + 5];
int numBytesToRead = Length;
int numBytesRead = 0;
while (numBytesToRead > 0){
int n;
n = readStream.Read(buffer, numBytesRead, numBytesToRead);
WriteStream.Write(buffer, numBytesRead, numBytesToRead);
numBytesRead += n;
numBytesToRead -= n;
}
readStream.Close();
writeStream.Close();
}