[英]Programmatically changing defaultproxy instead of using app.config
[英]set default proxy programmatically instead of using app.config
作為代理的后面,我的.Net 4.0 C#應用程序僅在存在具有以下內容的app.config時才有效:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy />
<bypasslist />
<module />
</defaultProxy>
</system.net>
既然我不想擁有app.config並且因為不建議嵌入app.config,那么與app.config中的xml chunk具有相同效果的C#代碼是什么?我在哪里放置它?
您可以使用WebRequest.DefaultWebProxy或GlobalProxySelection.Select
System.Net.GlobalProxySelection.Select = new WebProxy(ip,port);
要么
System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port);
以下代碼對我有用:
System.Net.WebRequest.DefaultWebProxy.Credentials
= System.Net.CredentialCache.DefaultNetworkCredentials;
您可以使用System.Net
WebProxy
WebProxy proxyObject = new WebProxy("PROXYIP",PORTNO);
WebRequest req = WebRequest.Create("http://www.stackoverflow.com");
req.Proxy = proxyObject;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.