Hello NG,
i have a problem With WebRequest!
i want to download a htaccess saved file over a proxyconnetion with
authentication.
Download a file what is not saved with htaccess is no problem, download a
htaccess saved file with out a
proxy with authentication i also no problem, but download this file with
htaccess and the auth proxy is a prob!
i use following code:
perhaps someone can help!
private void download()
{
string username = "user1";
string password = "password1";
string url = "proxyurl";
string dlurl "dlurl";
FileStream f = null;
NetworkCredential proxyCred = new NetworkCredential("user2",
"password2");
string[] localResources = {"192.168.*.*"};
WebProxy proxy = new WebProxy(new Uri("http://" +
url),true,localResources,proxyCred);
WebRequest request = WebRequest.Create(new Uri("http://" + dlurl));
request.Proxy = proxy;
if (username != "" && password != "")
{
NetworkCredential webCred = new NetworkCredential(username,
password);
request.Credentials = webCred;
}
try
{
request.Method = "GET";
request.ContentType = "binary/octet-stream";
WebResponse r = request.GetResponse();
long l = r.ContentLength;
System.IO.Stream respstream= r.GetResponseStream();
f = new FileStream("d:\\file.zip", FileMode.OpenOrCreate,
FileAccess.Write);
int BufferSize = 256;
byte[] recvbuffer = new byte[BufferSize];
long b = 0;
while (b < l)
{
int bytesread = respstream.Read(recvbuffer, 0, BufferSize);
f.Write(recvbuffer, 0, bytesread);
b += bytesread;
}
}
catch (System.Net.WebException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (f != null)
f.Close();
}
}
Looking forward for some help
Jörg Braun