设置默认的代理编程,而不是使用的app.config [英] set default proxy programmatically instead of using app.config
问题描述
作为一个代理之后,我的.Net 4.0 C#应用程序只能在有一个app.config包含以下内容:
Being behind a proxy, my .Net 4.0 C# application only works when there is an app.config with the following content:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy />
<bypasslist />
<module />
</defaultProxy>
</system.net>
现在,因为我不希望有一个app.config而且由于嵌入的app.config不推荐,什么是C#code具有同等效力XML块在App.config在哪里我把它?
Now since I don't want to have an app.config and since embedding app.config is not recommended, what is the C# code that has the same effect as that xml chunk in the app.config and where do I place it?
推荐答案
您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx">WebRequest.DefaultWebProxy或<一href="http://msdn.microsoft.com/en-us/library/system.net.globalproxyselection.aspx">GlobalProxySelection.Select
System.Net.GlobalProxySelection.Select = new WebProxy(ip,port);
或
System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port);
这篇关于设置默认的代理编程,而不是使用的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!