Using the WebProxy Class

There might be times when your application needs to communicate through a proxy server. When this is true, it would be advisable to use the WebProxy class so that you can have control over the communication. You can specify the name of the proxy server, the port through which you will be communicating, and whether to bypass the proxy server for local communications. The following code snippet shows how you can use the WebProxy class to make a Web request:

WebProxy proxyObject = new WebProxy( “http://MyProxyServer:80/”, true ); 
WebRequest req = WebRequest.Create( “http://www.SomeDomain.com” ); 
req.Proxy = proxyObject; 

When the proxy object is created, the name of the proxy server is specified (in this case, MyProxyServer), ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.