set default proxy programmatically instead of using app.config

[亡魂溺海] 提交于 2019-12-03 05:40:15

You can use WebRequest.DefaultWebProxy or GlobalProxySelection.Select

System.Net.GlobalProxySelection.Select = new WebProxy(ip,port);

OR

System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port);

The following code worked for me:

System.Net.WebRequest.DefaultWebProxy.Credentials 
    = System.Net.CredentialCache.DefaultNetworkCredentials;

you can use WebProxy from System.Net

WebProxy proxyObject = new WebProxy("PROXYIP",PORTNO);
WebRequest req = WebRequest.Create("http://www.stackoverflow.com");
req.Proxy = proxyObject;

More details at MSDN

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!