嗨 下面的代码工作正常,指示系统不要使用代理服务器而不自动检测代理服务器,这会导致无代码延迟。然而,在使用代理的网络上,我只是得到底层连接已关闭! 所以四个问题:Poxy代理问题! c#
- 我是否正确指定代理?
- 如果是这样,我该如何告诉它使用默认代理凭据?
- 应该使用想要指定凭据如何设置?
- 如何将其恢复到原始状态?
if (!Properties.Settings.Default.UseProxyServer){
//set the system not to use a proxy server
//saves the delay seen when browser set to auto detect proxy and not proxy
//is used. This works well!!
WebRequest.DefaultWebProxy = new WebProxy();
}
else{
WebRequest.DefaultWebProxy =
new WebProxy(proxyServerAddress, proxyServerPort);
//proxyServerPort is an int.
//How do I add default credentials??
}
WebClient client = new WebClient();
//specify an encoding for uploading.
client.Encoding = System.Text.Encoding.ASCII;
// Upload the data.
var myReply = client.UploadValues(addressURL, data);
我需要这个代码不是在app.config中。
感谢
感谢,但我需要更改默认代理。 我想我有它!但我需要等到使用代理服务器回到网络时,我现在正在执行以下操作。 WebProxy wp = new WebProxy(proxyServerAddress); wp.UseDefaultCredentials = true; WebRequest.DefaultWebProxy = wp; – Adrian 2010-10-12 20:35:22