By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 2,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

Problem downloading a file saved by htaccess over a proxy with authentication

P: n/a
Hello NG,

i have a problem With WebRequest!

i want to download a htaccess saved file over a proxyconnetion with
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",
string[] localResources = {"192.168.*.*"};
WebProxy proxy = new WebProxy(new Uri("http://" +

WebRequest request = WebRequest.Create(new Uri("http://" + dlurl));

request.Proxy = proxy;
if (username != "" && password != "")
NetworkCredential webCred = new NetworkCredential(username,
request.Credentials = webCred;
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:\\", FileMode.OpenOrCreate,
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)
catch (Exception ex)
if (f != null)

Looking forward for some help

Jörg Braun
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.