Export (0) Print
Expand All
6 out of 9 rated this helpful - Rate this topic

WebProxy Class

Contains HTTP proxy settings for the WebRequest class.

Namespace: System.Net
Assembly: System (in system.dll)

[SerializableAttribute] 
public class WebProxy : IWebProxy, ISerializable
/** @attribute SerializableAttribute() */ 
public class WebProxy implements IWebProxy, ISerializable
SerializableAttribute 
public class WebProxy implements IWebProxy, ISerializable
Not applicable.

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:

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 IWebProxyScript class.)

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = 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);

System.Object
  System.Net.WebProxy
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.