O
Ofer B.
Hi all
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();
do any body know how to solve it?
this is the all function
---------------------------------------------------------------------------
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now
fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}
I had some code that works fine till the SP2.
I try to download a file from the internet.
after the sp2 I get "WebExeption" for this line: response =
(HttpWebResponse)request.GetResponse();
do any body know how to solve it?
this is the all function
---------------------------------------------------------------------------
/// <summary>
/// connect to an internet link, download data, and save it to a file.
/// </summary>
private void DownloadData(string link, string file)
{
HttpWebRequest request;
HttpWebResponse response;
Stream ReceiveStream = null;
FileStream fstr = null;
try
{
request = (HttpWebRequest)WebRequest.Create(link);
request.Credentials = new NetworkCredential(this.txtUserName.Text ,
this.txtUserPass.Text);
response = (HttpWebResponse)request.GetResponse();
ReceiveStream = response.GetResponseStream();
// Now read s into a byte buffer.
byte[] bytes = new byte[100000];
int numBytesToRead = (int)bytes.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n==0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
ReceiveStream.Close();
// numBytesToRead should be 0 now
fstr = new FileStream(file, FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(bytes, 0, numBytesRead);
fstr.Close();
}
catch(WebException we)
{
throw we;
}
catch(Exception ex)
{
throw ex;
}
finally
{
request = null;
response = null;
}
}