Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Accessing the Internet Through a Proxy

Accessing the Internet Through a Proxy

If your site uses a proxy to provide access to the Internet, you must configure a proxy instance to enable your application to communicate with the Web proxy.

The following code example creates a global proxy instance that will enable any WebRequest to use a proxy to communicate with the Internet. The example assumes that the proxy server is named webproxy and that it communicates on port 80, the standard HTTP port.

WebProxy proxyObject = new WebProxy("http://webproxy:80/");
GlobalProxySelection.Select = proxyObject;
[Visual Basic]
Dim proxyObject As WebProxy = New WebProxy("http://webproxy:80/")
GlobalProxySelection.Select = proxyObject

You can override the global proxy selection by assigning an instance that implements the IWebProxy interface to the Proxy property of your WebRequest. The following code example sends a WebRequest to www.contoso.com that overrides the global proxy selection with a proxy server named alternateproxy on port 80.

WebRequest req = new WebRequest.Create("http://www.contoso.com/");
req.Proxy = new WebProxy("http://alternateproxy:80/");
[Visual Basic]
Dim req As WebRequest = new WebRequest.Create("http://www.contoso.com/")
req.Proxy = New WebProxy("http://alternateproxy:80/")

See Also

Using Application Protocols | Accessing the Internet

Show:
© 2015 Microsoft