5 out of 14 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

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 null. 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(S"http://proxyserver:80/",true);
WebRequest* req = WebRequest::Create(S"http://www.contoso.com");
req->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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
New Technique to replace obsolete GetDefaultProxy
It is now handled in the configs under:
<system.net>
<defaultProxy>
<proxy usesystemdefault="true" />
</defaultProxy>
</system.net>
Which then applies the system proxy settings as specified to all connections in your application.
good to know!

OR you can read the registry settings and evaluate them yourself and copy them to a new proxy.
407 Proxy Authentication

If you get this error, please see the following:

http://forums.lhotka.net/forums/post/29271.aspx

Documentation is out of date or inaccurate
The GetDefaultProxy method is listed as obsolete yet this documentation continues to provide information about it's detail as if it is not.