The "WebClient" class (and ClickOnce also) can use default proxy settings (e.g. put in application.config), however:
http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx
<defaultProxy
enabled="true|false"
useDefaultCredentials="true|false"
<bypasslist> … </bypasslist>
<proxy> … </proxy>
<module> … </module>
/>
PS. I've just been testing with the following below setup and confirmed that the Username/Password does not come from a successful logged on IE session.
Outstanding question is therefore where would the username/password come from? Or does it have to be programmatically supplied within the custom application, in which case what happens with ClickOnce then? (which doesn't seem to launch any dialog to allow a user to supply the username/password)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="false">
<bypasslist>
<add address="localhost" />
</bypasslist>
<proxy usesystemdefault="True" proxyaddress="http://proxy1.health.qld.gov.au:80/" bypassonlocal="False" />
</defaultProxy>
</system.net>
</configuration>
private void button2_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
var wc = new WebClient();
var str = wc.DownloadString(textBox1.Text);
MessageBox.Show("String = " + str);
}
finally
{
Cursor.Current = Cursors.Default;
}
}
The credentials come from your network settings. You can easily set them manually in code, simply use the WebProxy class.
WebProxy proxy = new WebProxy("http://yourproxyserveraddress");
NetworkCredential cred = new NetworkCredential("user","password","domain");
proxy.Credentials = cred;
HttpWebRequest.DefaultWebProxy = proxy;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With