K
kkb
Hello!
First, I'm sorry because of my english... I'll try to be
understandable!
I've got a strange problem using .NET 2003 C# and I haven't figured it
out for a long time. I'm implementing an application to download images
using System.NET classes (webclient, webrequest) asynchronously behind
proxy server. The reading method works like this:
System.Net.WebClient client=new System.Net.WebClient();
client.Credentials=System.Net.CredentialCache.DefaultCredentials;
while(!isEnded)
{
webRequest=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Credentials=System.Net.CredentialCache.DefaultCredentials;
webRequest.Timeout=10000;
webRequest.Proxy=System.Net.WebProxy.GetDefaultProxy();
webResponse=(System.Net.HttpWebResponse)webRequest.GetResponse();
fileSize=webResponse.ContentLength;
strResponse=client.OpenRead(url);
strLocal=new
System.IO.FileStream(filename,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.None);
downBuffer=new byte[2048];
while(strLocal.Length<fileSize)
{
strResponse.BeginRead(downBuffer,0,downBuffer.Length,new
System.AsyncCallback(streamreaded),strResponse);
strLocal.Write(downBuffer,0,readed);
}
strLocal.Close();
strResponse.Close();
webResponse.Close();
}
The main loop managed to download several files.
So, the problem is the following: the read method (beginread) always
hangs in time, undeterminately. It downloads some files and then
somewhere (in the middle of a download) it stops the transfer and
hangs. I've found that if I've downloaded the file using my browser
(Firefox) before, than there will be no problem with that file -
strange... The proxy is set properly. I'm getting crazy with this. If
anyone would help me, please do it!
Thanks a lot!
Kornel
First, I'm sorry because of my english... I'll try to be
understandable!
I've got a strange problem using .NET 2003 C# and I haven't figured it
out for a long time. I'm implementing an application to download images
using System.NET classes (webclient, webrequest) asynchronously behind
proxy server. The reading method works like this:
System.Net.WebClient client=new System.Net.WebClient();
client.Credentials=System.Net.CredentialCache.DefaultCredentials;
while(!isEnded)
{
webRequest=(System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Credentials=System.Net.CredentialCache.DefaultCredentials;
webRequest.Timeout=10000;
webRequest.Proxy=System.Net.WebProxy.GetDefaultProxy();
webResponse=(System.Net.HttpWebResponse)webRequest.GetResponse();
fileSize=webResponse.ContentLength;
strResponse=client.OpenRead(url);
strLocal=new
System.IO.FileStream(filename,System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.None);
downBuffer=new byte[2048];
while(strLocal.Length<fileSize)
{
strResponse.BeginRead(downBuffer,0,downBuffer.Length,new
System.AsyncCallback(streamreaded),strResponse);
strLocal.Write(downBuffer,0,readed);
}
strLocal.Close();
strResponse.Close();
webResponse.Close();
}
The main loop managed to download several files.
So, the problem is the following: the read method (beginread) always
hangs in time, undeterminately. It downloads some files and then
somewhere (in the middle of a download) it stops the transfer and
hangs. I've found that if I've downloaded the file using my browser
(Firefox) before, than there will be no problem with that file -
strange... The proxy is set properly. I'm getting crazy with this. If
anyone would help me, please do it!
Thanks a lot!
Kornel