public class WebProxy : IWebProxy
Object
WebProxyThis type implements IWebProxy.
System
Networking
Contains HTTP proxy settings for the WebRequest class.
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/ ".]
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; } }
System.Net Namespace
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
public WebProxy();
Constructs and initializes a new instance of the WebProxy class.
This constructor initializes the properties of the new instance as follows.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(Uri Address);
Constructs and initializes a new instance of the WebProxy class using the specified Uri .
- Address
- A Uri containing the address of the proxy server.
This constructor initializes the properties of the new instance as follows.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(Uri Address, bool BypassOnLocal);
Constructs and initializes a new instance of the WebProxy class using the specified Uri and specified bypass setting.
- 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
.
The properties of the new instance are initialized as detailed in the following table.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList);
Constructs a new instance of the WebProxy class with the specified Uri , bypass setting, and list of URIs to bypass.
- 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.]
This constructor initializes the properties of the new instance as follows.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials);
Constructs and initializes a new instance of the WebProxy class with the specified Uri , bypass setting, list of URIs to bypass, and credentials.
- 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.
This constructor initializes the properties of the new instance as follows.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(string Host, int Port);
Constructs and initializes a new instance of the WebProxy class with the specified host and port number.
- Host
- A String containing the name of the proxy server.
- Port
- A Int32 that contains the port number to use when accessing Host .
Exception Type Condition UriFormatException The URI formed by combining Host and Port is not in a valid URI format.
This constructor initializes the properties of the new instance as follows.
Property Value 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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(string Address);
Constructs and initializes a new instance of the WebProxy class with the specified URI.
- Address
- A String containing the URI of the proxy server.
Exception Type Condition UriFormatException Address is not null
and not in a valid URI format.
This constructor initializes the properties of the new instance as follows.
Property Value 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 tonull
.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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(string Address, bool BypassOnLocal);
Constructs and initializes a new instance of the WebProxy class with the specified URI and bypass setting.
- 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
.
Exception Type Condition UriFormatException Address is not in a valid URI format.
This constructor initializes the properties of the new instance as follows.
Property Value 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 tonull
.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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(string Address, bool BypassOnLocal, string[] BypassList);
Constructs and initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass.
- 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.]
Exception Type Condition UriFormatException Address is not in a valid URI format.
This constructor initializes the properties of the new instance as follows.
Property Value 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 tonull
.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
System.Net.WebProxy Class, System.Net Namespace
public WebProxy(string Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials);
Constructs and initializes a new instance of the WebProxy class with the specified URI, bypass setting, list of URIs to bypass, and credentials.
- 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.
Exception Type Condition UriFormatException Address is not in a valid URI format.
This constructor initializes the properties of the new instance as follows.
Property Value 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 tonull
.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
System.Net.WebProxy Class, System.Net Namespace
public static WebProxy GetDefaultProxy();
Returns a new WebProxy instance that contains the default proxy settings of the system.
A new WebProxy instance that contains the default proxy settings of the system.
The default proxy settings of the system are implementation-defined.
System.Net.WebProxy Class, System.Net Namespace
public Uri GetProxy(Uri destination);
Returns the URI of the server that is contacted for the specified resource.
- destination
- The Uri of the requested resource.
If destination is on the bypass list of the current instance, returns destination; otherwise, returns the System.Net.WebProxy.Address of the current instance.
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.
System.Net.WebProxy Class, System.Net Namespace
public bool IsBypassed(Uri host);
Indicates whether a request will bypass the proxy server when accessing the resource represented by the specified URI.
- host
- A Uri containing the URI of the server to check.
Returnstrue
under any of the following conditions:
All other conditions return
- The System.Net.WebProxy.BypassProxyOnLocal property of the current instance is
true
and host is a local URI.- host matches a regular expression in System.Net.WebProxy.BypassList.
- The System.Net.WebProxy.Address of the current instance is
null
.false
.
Exception Type Condition ArgumentException The System.Net.WebProxy.BypassList of the current instance contains an invalid regular expression.
System.Net.WebProxy Class, System.Net Namespace
public Uri Address { get; set; }
Gets or sets the address of the proxy server represented by the current instance.
A Uri containing the address of the proxy server represented by the current instance.
[Note: When System.Net.WebProxy.Address isnull
, 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.
]
System.Net.WebProxy Class, System.Net Namespace
public ArrayList BypassArrayList { get; }
Gets a list of the URIs that do not use the proxy server.
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.
This property is read-only.
System.Net.WebProxy Class, System.Net Namespace
public string[] BypassList { get; set; }
Gets or sets an array of the URIs that do not use the proxy server.
A Array of String instances. The elements of the array represent URIs that a WebRequest instance accesses directly instead of through the proxy server.
This property is equivalent to System.Net.WebProxy.BypassArrayList.ToArray
(typeof
(String)).
System.Net.WebProxy Class, System.Net Namespace
public bool BypassProxyOnLocal { get; set; }
Gets or sets a Boolean value indicating whether requests for local resources bypass the proxy server.
true
to bypass the proxy server for local resources; otherwise,false
. The default value isfalse
.
The setting of this property determines whether WebRequest instances use the proxy server when accessing local resources. If System.Net.WebProxy.BypassProxyOnLocal istrue
, 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 isfalse
, 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.]
System.Net.WebProxy Class, System.Net Namespace
public ICredentials Credentials { get; set; }
Gets or sets the credentials to submit to the proxy server for authentication.
A ICredentials object containing the credentials to submit to the proxy server for authentication.
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.]
System.Net.WebProxy Class, System.Net Namespace