开发者

how to add proxy in c#

开发者 https://www.devze.com 2022-12-16 17:04 出处:网络
i have created a application in c# i wa开发者_StackOverflow中文版nt to add proxy server how can i do it.You can set a global proxy that way

i have created a application in c# i wa开发者_StackOverflow中文版nt to add proxy server how can i do it.


You can set a global proxy that way

System.Net.Uri proxyURI = new System.Net.Uri("http://64.202.165.130:3128");
System.Net.GlobalProxySelection.Select = new System.Net.WebProxy(proxyURI);

Or set it for a WebRequest like this:

var proxyURI = new System.Net.Uri("http://64.202.165.130:3128");
var proxy = new System.Net.WebProxy(proxyURI);

// If u need passwords:
proxy.Credentials=new NetworkCredential(username,password);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com");
request.Proxy = proxy;


}


If you mean you using webclient to access some URLs then you can use following code to set proxy for it. So that your request will tunnel through proxy server.

WebClient wc = new WebClient();
wc.Proxy = new WebProxy("proxyServer", 8080);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号