System.Net.WebProxy Class

public class WebProxy : IWebProxy

Base Types

Object
  WebProxy

This type implements IWebProxy.

Assembly

System

Library

Networking

Summary

Contains HTTP proxy settings for the WebRequest class.

Description

WebRequest instances use WebProxy instances to override the proxy settings in GlobalProxySelection .

[Note: Local requests are identified by the lack of a period (.) in the authority of the URI, as in "http://webserver/" versus "http://www.contoso.com/ ".]

Example

The following example sets a WebProxy for a WebRequest. The WebRequest instance uses the proxy to connect to external Internet resources.

using System;
using System.Net;

public class WebProxyExample {

  public static void Main() {

    WebProxy proxyObject =
      new WebProxy("http://proxyserver:80/",true);
    WebRequest req =
      WebRequest.Create("http://www.contoso.com");
    req.Proxy = proxyObject;
  }
}

See Also

System.Net Namespace

Members

WebProxy Constructors

WebProxy() Constructor
WebProxy(System.Uri) Constructor
WebProxy(System.Uri, bool) Constructor
WebProxy(System.Uri, bool, System.String[]) Constructor
WebProxy(System.Uri, bool, System.String[], System.Net.ICredentials) Constructor
WebProxy(System.String, int) Constructor
WebProxy(System.String) Constructor
WebProxy(System.String, bool) Constructor
WebProxy(System.String, bool, System.String[]) Constructor
WebProxy(System.String, bool, System.String[], System.Net.ICredentials) Constructor

WebProxy Methods

WebProxy.GetDefaultProxy Method
WebProxy.GetProxy Method
WebProxy.IsBypassed Method

WebProxy Properties

WebProxy.Address Property
WebProxy.BypassArrayList Property
WebProxy.BypassList Property
WebProxy.BypassProxyOnLocal Property
WebProxy.Credentials Property


WebProxy() Constructor

public WebProxy();

Summary

Constructs and initializes a new instance of the WebProxy class.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

null
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

false
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.Uri) Constructor

public WebProxy(Uri Address);

Summary

Constructs and initializes a new instance of the WebProxy class using the specified Uri .

Parameters

Address
A Uri containing the address of the proxy server.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

Address
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

false
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.Uri, bool) Constructor

public WebProxy(Uri Address, bool BypassOnLocal);

Summary

Constructs and initializes a new instance of the WebProxy class using the specified Uri and specified bypass setting.

Parameters

Address
A Uri containing the address of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

Description

The properties of the new instance are initialized as detailed in the following table.

PropertyValue
System.Net.WebProxy.Address

Address
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.Uri, bool, System.String[]) Constructor

public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList);

Summary

Constructs a new instance of the WebProxy class with the specified Uri , bypass setting, and list of URIs to bypass.

Parameters

Address
A Uri containing the address of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

BypassList
A String array of regular expressions that describe the URIs that will not be accessed using the current instance. [Note: For more information on the format of these regular expressions, see IETF RFC 2396, Appendix B.]

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

Address
System.Net.WebProxy.BypassArrayList

A new ArrayList constructed from BypassList or, if BypassList is null , a new empty ArrayList.
System.Net.WebProxy.BypassList

BypassList or, if BypassList is null , a new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.Uri, bool, System.String[], System.Net.ICredentials) Constructor

public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified Uri , bypass setting, list of URIs to bypass, and credentials.

Parameters

Address
A Uri containing the address of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

BypassList
A String array of regular expressions that describe the URIs that will not be accessed using the current instance. [Note: For more information on the format of these regular expressions, see IETF RFC 2396, Appendix B.]

Credentials
A ICredentials object to submit to the proxy server for client authentication.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

Address
System.Net.WebProxy.BypassArrayList

A new ArrayList constructed from BypassList or, if BypassList is null , a new empty ArrayList.
System.Net.WebProxy.BypassList

BypassList or, if BypassList is null , a new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

Credentials

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.String, int) Constructor

public WebProxy(string Host, int Port);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified host and port number.

Parameters

Host
A String containing the name of the proxy server.
Port
A Int32 that contains the port number to use when accessing Host .

Exceptions

Exception TypeCondition
UriFormatExceptionThe URI formed by combining Host and Port is not in a valid URI format.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

A new Uri constructed from "http://Host:Port".
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

false
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.String) Constructor

public WebProxy(string Address);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified URI.

Parameters

Address
A String containing the URI of the proxy server.

Exceptions

Exception TypeCondition
UriFormatExceptionAddress is not null and not in a valid URI format.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

A new Uri constructed from Address or, if Address does not contain "://", constructed from "http://Address". If Address is null , this property is set to null .
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

false
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.String, bool) Constructor

public WebProxy(string Address, bool BypassOnLocal);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified URI and bypass setting.

Parameters

Address
A String that represents the URI of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

Exceptions

Exception TypeCondition
UriFormatExceptionAddress is not in a valid URI format.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

A new Uri constructed from Address or, if Address does not contain "://", constructed from "http://Address". If Address is null , this property is set to null .
System.Net.WebProxy.BypassArrayList

A new empty ArrayList.
System.Net.WebProxy.BypassList

A new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.String, bool, System.String[]) Constructor

public WebProxy(string Address, bool BypassOnLocal, string[] BypassList);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass.

Parameters

Address
A String that represents the URI of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

BypassList
A String array of regular expressions that describe the URIs that will not be accessed using the current instance. [Note: For more information on the format of these regular expressions, see IETF RFC 2396, Appendix B.]

Exceptions

Exception TypeCondition
UriFormatExceptionAddress is not in a valid URI format.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

A new Uri constructed from Address or, if Address does not contain "://", constructed from "http://Address". If Address is null , this property is set to null .
System.Net.WebProxy.BypassArrayList

A new ArrayList constructed from BypassList or, if BypassList is null , a new empty ArrayList.
System.Net.WebProxy.BypassList

BypassList or, if BypassList is null , a new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

null

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy(System.String, bool, System.String[], System.Net.ICredentials) Constructor

public WebProxy(string Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials);

Summary

Constructs and initializes a new instance of the WebProxy class with the specified URI, bypass setting, list of URIs to bypass, and credentials.

Parameters

Address
A String that represents the URI of the proxy server.
BypassOnLocal
A Boolean that indicates whether or not to bypass the proxy for local connections. Specify true to bypass the proxy for local connections; otherwise, false .

BypassList
A String array of regular expressions that describe the URIs that will not be accessed using the current instance. [Note: For more information on the format of these regular expressions, see IETF RFC 2396, Appendix B.]

Credentials
A ICredentials object to submit to the proxy server for client authentication.

Exceptions

Exception TypeCondition
UriFormatExceptionAddress is not in a valid URI format.

Description

This constructor initializes the properties of the new instance as follows.

PropertyValue
System.Net.WebProxy.Address

A new Uri constructed from Address or, if Address does not contain "://", constructed from "http://Address". If Address is null , this property is set to null .
System.Net.WebProxy.BypassArrayList

A new ArrayList constructed from BypassList or, if BypassList is null , a new empty ArrayList.
System.Net.WebProxy.BypassList

BypassList or, if BypassList is null , a new empty String array.
System.Net.WebProxy.BypassProxyOnLocal

BypassOnLocal
System.Net.WebProxy.Credentials

Credentials

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.GetDefaultProxy Method

public static WebProxy GetDefaultProxy();

Summary

Returns a new WebProxy instance that contains the default proxy settings of the system.

Return Value

A new WebProxy instance that contains the default proxy settings of the system.

Description

The default proxy settings of the system are implementation-defined.

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.GetProxy Method

public Uri GetProxy(Uri destination);

Summary

Returns the URI of the server that is contacted for the specified resource.

Parameters

destination
The Uri of the requested resource.

Return Value

If destination is on the bypass list of the current instance, returns destination; otherwise, returns the System.Net.WebProxy.Address of the current instance.

Description

This method returns the URI that the WebRequest uses to access the resource. System.Net.WebProxy.GetProxy(System.Uri) compares destination with the contents of System.Net.WebProxy.BypassList using the System.Net.WebProxy.IsBypassed(System.Uri) method.

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.IsBypassed Method

public bool IsBypassed(Uri host);

Summary

Indicates whether a request will bypass the proxy server when accessing the resource represented by the specified URI.

Parameters

host
A Uri containing the URI of the server to check.

Return Value

Returns true under any of the following conditions:

All other conditions return false .

Exceptions

Exception TypeCondition
ArgumentExceptionThe System.Net.WebProxy.BypassList of the current instance contains an invalid regular expression.

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.Address Property

public Uri Address { get; set; }

Summary

Gets or sets the address of the proxy server represented by the current instance.

Property Value

A Uri containing the address of the proxy server represented by the current instance.

Description

[Note: When System.Net.WebProxy.Address is null , all requests that reference the current instance bypass the proxy and connect directly to the destination host.

For additional information, see System.Net.WebRequest.Proxy.

]

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.BypassArrayList Property

public ArrayList BypassArrayList { get; }

Summary

Gets a list of the URIs that do not use the proxy server.

Property Value

A ArrayList of String instances. The elements of the list represent the URIs that a WebRequest instance accesses directly instead of through the proxy server.

Description

This property is read-only.

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.BypassList Property

public string[] BypassList { get; set; }

Summary

Gets or sets an array of the URIs that do not use the proxy server.

Property Value

A Array of String instances. The elements of the array represent URIs that a WebRequest instance accesses directly instead of through the proxy server.

Description

This property is equivalent to System.Net.WebProxy.BypassArrayList.ToArray (typeof (String)).

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.BypassProxyOnLocal Property

public bool BypassProxyOnLocal { get; set; }

Summary

Gets or sets a Boolean value indicating whether requests for local resources bypass the proxy server.

Property Value

true to bypass the proxy server for local resources; otherwise, false . The default value is false .

Description

The setting of this property determines whether WebRequest instances use the proxy server when accessing local resources. If System.Net.WebProxy.BypassProxyOnLocal is true , requests to local resources do not use the proxy server. Local resources are identified by the lack of a period (.) in the URI, as in "http://webserver/". When System.Net.WebProxy.BypassProxyOnLocal is false , all requests for resources are made through the proxy server.

[Note: If a request for a resource residing on a local machine is made using a URI that contains a period, the proxy is used to send the request. Create an entity in the System.Net.WebProxy.BypassList to access local resources directly.]

See Also

System.Net.WebProxy Class, System.Net Namespace

WebProxy.Credentials Property

public ICredentials Credentials { get; set; }

Summary

Gets or sets the credentials to submit to the proxy server for authentication.

Property Value

A ICredentials object containing the credentials to submit to the proxy server for authentication.

Description

This property contains the authentication credentials to send to the proxy server in response to an HTTP 407 (proxy authorization) status code.

[Note: For more information regarding HTTP status code 407, see System.Net.HttpStatusCode.ProxyAuthenticationRequired.]

See Also

System.Net.WebProxy Class, System.Net Namespace