嗨 下面的代碼工作正常,指示系統不要使用代理服務器而不自動檢測代理服務器,這會導致無代碼延遲。然而,在使用代理的網絡上,我只是得到底層連接已關閉! 所以四個問題: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