作为一个代理之后,我的.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?
您可以使用WebRequest.DefaultWebProxy或GlobalProxySelection.Select
System.Net.GlobalProxySelection.Select = new WebProxy(ip,port);
或
System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port);