System.Net.WebClient with Proxy and Credentials

T

TheMaxx

I try getting response from web site through proxy in my domain:

WebClient wc = new WebClient();
WebProxy wProxy = new WebProxy();

CredentialCache cc = new CredentialCache();
NetworkCredential nc = new NetworkCredential("myUsername", "myPassword",
"myDomain");
cc.Add("myProxy.domain.local", 8080, "Basic", nc);
// should this be: cc.Add("http://myProxy.domain.local", 8080, "Basic", nc);
?? got same error

wProxy.Credentials = cc;
wc.Proxy = wProxy;

string html = wc.DownloadString(new Uri("http://www.google.com/"));

MessageBox.Show(this, html);


I get error:
Message : Unable to connect to the remote server
InnerException : A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond


Is there a way to test just getting to proxy server and/or passing through
it?

Thanx.
 
G

Guest

This is one way that I do it:

WebProxy p = null;
string proxyAddressAndPort =
ConfigurationManager.AppSettings["proxy"];
string proxyUserName =
ConfigurationManager.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationManager.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
WebRequest.DefaultWebProxy = p;

-That's for ASP.NET 2.0 , the last line for ASP.NET 1.1 would be like yours.

The IP address of the actual proxy server and port would look like:

10.10.128.3:8080


Peter
 
T

TheMaxx

Thanx!
this worked for me!

now i'll try to find out what's wrong with my code.
:)


Peter Bromberg said:
This is one way that I do it:

WebProxy p = null;
string proxyAddressAndPort =
ConfigurationManager.AppSettings["proxy"];
string proxyUserName =
ConfigurationManager.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationManager.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
WebRequest.DefaultWebProxy = p;

-That's for ASP.NET 2.0 , the last line for ASP.NET 1.1 would be like
yours.

The IP address of the actual proxy server and port would look like:

10.10.128.3:8080


Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




TheMaxx said:
I try getting response from web site through proxy in my domain:

WebClient wc = new WebClient();
WebProxy wProxy = new WebProxy();

CredentialCache cc = new CredentialCache();
NetworkCredential nc = new NetworkCredential("myUsername",
"myPassword",
"myDomain");
cc.Add("myProxy.domain.local", 8080, "Basic", nc);
// should this be: cc.Add("http://myProxy.domain.local", 8080, "Basic",
nc);
?? got same error

wProxy.Credentials = cc;
wc.Proxy = wProxy;

string html = wc.DownloadString(new Uri("http://www.google.com/"));

MessageBox.Show(this, html);


I get error:
Message : Unable to connect to the remote server
InnerException : A connection attempt failed because the connected party
did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond


Is there a way to test just getting to proxy server and/or passing
through
it?

Thanx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top