WebProxy Class
Assembly: System (in system.dll)
'Declaration <SerializableAttribute> _ Public Class WebProxy Implements IWebProxy, ISerializable 'Usage Dim instance As WebProxy
/** @attribute SerializableAttribute() */ public class WebProxy implements IWebProxy, ISerializable
SerializableAttribute public class WebProxy implements IWebProxy, ISerializable
The WebProxy class contains the proxy settings that WebRequest instances use to determine whether a Web proxy is used to send requests. Global Web proxy settings can be specified in machine and application configuration files, and applications can use instances of the WebProxy class to customize Web proxy use. The WebProxy class is the base implementation of the IWebProxy interface.
To obtain instances of the Web proxy class, you can use any of the following methods:
-
The WebProxy constructor.
-
The GetDefaultProxy method.
-
The Select method.
These methods each supply a WebProxy instance that you can further customize; the difference between them is how the instance is initialized before it is returned to your application. The WebProxy constructor returns an instance of the WebProxy class with the Address property set to a null reference (Nothing in Visual Basic). When a request uses a WebProxy instance in this state, no proxy is used to send the request.
The GetDefaultProxy method returns an instance of the WebProxy class with the Address, BypassProxyOnLocal, and BypassList properties set to the values used by Internet Explorer 5.5 and later.
The Select method returns an instance of the WebProxy class with it properties set according to a combination of Internet Explorer and configuration file settings.
The WebProxy class supports automatic detection and execution of proxy configuration scripts. This feature is also known as Web Proxy Auto-Discovery (WPAD). When using automatic proxy configuration, a configuration script, typically named Wpad.dat, must be located, downloaded, compiled, and run. If these operations are successful, the script returns the proxies that can be used for a request.
The following code example assigns a WebProxy instance to a WebRequest instance. The WebRequest instance uses the proxy to connect to external Internet resources. (For an example that demonstrates using the WPAD feature, see the documentation for the AutomaticConfigurationScript property.)
Dim proxyObject As New WebProxy("http://proxyserver:80/", True) Dim req As WebRequest = WebRequest.Create("http://www.contoso.com") req.Proxy = proxyObject
WebProxy proxyObject = new WebProxy("http://proxyserver:80/", true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.set_Proxy(proxyObject);
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.