Bewerken

Share via


WebProxy Constructors

Definition

Initializes a new instance of the WebProxy class.

Overloads

WebProxy()

Initializes an empty instance of the WebProxy class.

WebProxy(String, Boolean, String[], ICredentials)

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

WebProxy(Uri, Boolean, String[])

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

WebProxy(String, Boolean, String[])

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

WebProxy(Uri, Boolean)

Initializes a new instance of the WebProxy class with the Uri instance and bypass setting.

WebProxy(Uri, Boolean, String[], ICredentials)

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

WebProxy(String, Boolean)

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

WebProxy(SerializationInfo, StreamingContext)
Obsolete.

Initializes an instance of the WebProxy class using previously serialized content.

WebProxy(Uri)

Initializes a new instance of the WebProxy class from the specified Uri instance.

WebProxy(String)

Initializes a new instance of the WebProxy class with the specified URI.

WebProxy(String, Int32)

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

WebProxy()

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

Initializes an empty instance of the WebProxy class.

public:
 WebProxy();
public WebProxy ();
Public Sub New ()

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxy()
{
   return gcnew WebProxy;
}
public static WebProxy CreateProxy()
{
    return new WebProxy();
}

Remarks

The parameterless constructor initializes an empty instance of the WebProxy class with the Address property set to null.

When the Address property is null, the IsBypassed method returns true and the GetProxy method returns the destination address.

Applies to

WebProxy(String, Boolean, String[], ICredentials)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(System::String ^ Address, bool BypassOnLocal, cli::array <System::String ^> ^ BypassList, System::Net::ICredentials ^ Credentials);
public WebProxy (string? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials);
public WebProxy (string Address, bool BypassOnLocal, string[] BypassList, System.Net.ICredentials Credentials);
new System.Net.WebProxy : string * bool * string[] * System.Net.ICredentials -> System.Net.WebProxy
Public Sub New (Address As String, BypassOnLocal As Boolean, BypassList As String(), Credentials As ICredentials)

Parameters

Address
String

The URI of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

BypassList
String[]

An array of regular expression strings that contains the URIs of the servers to bypass.

Credentials
ICredentials

An ICredentials instance to submit to the proxy server for authentication.

Exceptions

Address is an invalid URI.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithCredentials( bool bypassLocal )
{
   // Do not use the proxy server for Contoso.com URIs.
   array<String^>^ bypassList = {";*.Contoso.com"};
   return gcnew WebProxy( "http://contoso",
      bypassLocal,
      bypassList,
      CredentialCache::DefaultCredentials );
}
public static WebProxy CreateProxyWithCredentials(bool bypassLocal)
{
    // Do not use the proxy server for Contoso.com URIs.
    string[] bypassList = new string[]{";*.Contoso.com"};
    return new WebProxy("http://contoso",
        bypassLocal,
        bypassList,
        CredentialCache.DefaultCredentials);
}

Remarks

The WebProxy instance is initialized with the Address property set to a Uri instance that contains Address, the BypassProxyOnLocal property set to BypassOnLocal, the BypassList property set to BypassList, and the Credentials property set to Credentials.

See also

Applies to

WebProxy(Uri, Boolean, String[])

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(Uri ^ Address, bool BypassOnLocal, cli::array <System::String ^> ^ BypassList);
public WebProxy (Uri? Address, bool BypassOnLocal, string[]? BypassList);
public WebProxy (Uri Address, bool BypassOnLocal, string[] BypassList);
new System.Net.WebProxy : Uri * bool * string[] -> System.Net.WebProxy
Public Sub New (Address As Uri, BypassOnLocal As Boolean, BypassList As String())

Parameters

Address
Uri

A Uri instance that contains the address of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

BypassList
String[]

An array of regular expression strings that contains the URIs of the servers to bypass.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithBypassList( bool bypassLocal )
{
   // Do not use the proxy server for Contoso.com URIs.
   array<String^>^ bypassList = {";*.Contoso.com"};
   return gcnew WebProxy( gcnew Uri( "http://contoso" ),
      bypassLocal,
      bypassList );
}
public static WebProxy CreateProxyWithBypassList(bool bypassLocal)
{
    // Do not use the proxy server for Contoso.com URIs.
    string[] bypassList = new string[]{";*.Contoso.com"};
    return new WebProxy(new Uri("http://contoso"),
        bypassLocal,
        bypassList);
}

Remarks

The WebProxy instance is initialized with the Address property set to Address, the BypassProxyOnLocal property set to BypassOnLocal, and the BypassList property set to BypassList.

Applies to

WebProxy(String, Boolean, String[])

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(System::String ^ Address, bool BypassOnLocal, cli::array <System::String ^> ^ BypassList);
public WebProxy (string? Address, bool BypassOnLocal, string[]? BypassList);
public WebProxy (string Address, bool BypassOnLocal, string[] BypassList);
new System.Net.WebProxy : string * bool * string[] -> System.Net.WebProxy
Public Sub New (Address As String, BypassOnLocal As Boolean, BypassList As String())

Parameters

Address
String

The URI of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

BypassList
String[]

An array of regular expression strings that contain the URIs of the servers to bypass.

Exceptions

Address is an invalid URI.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithHostAndBypassList( bool bypassLocal )
{
   // Do not use the proxy server for Contoso.com URIs.
   array<String^>^ bypassList = {";*.Contoso.com"};
   return gcnew WebProxy( "http://contoso",
      bypassLocal,
      bypassList );
}
public static WebProxy CreateProxyWithHostAndBypassList(bool bypassLocal)
{
    // Do not use the proxy server for Contoso.com URIs.
    string[] bypassList = new string[]{";*.Contoso.com"};
    return new WebProxy("http://contoso",
        bypassLocal,
        bypassList);
}

Remarks

The WebProxy instance is initialized with the Address property set to a Uri instance that contains Address, the BypassProxyOnLocal property set to BypassOnLocal, and the BypassList property set to BypassList.

See also

Applies to

WebProxy(Uri, Boolean)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

Initializes a new instance of the WebProxy class with the Uri instance and bypass setting.

public:
 WebProxy(Uri ^ Address, bool BypassOnLocal);
public WebProxy (Uri? Address, bool BypassOnLocal);
public WebProxy (Uri Address, bool BypassOnLocal);
new System.Net.WebProxy : Uri * bool -> System.Net.WebProxy
Public Sub New (Address As Uri, BypassOnLocal As Boolean)

Parameters

Address
Uri

A Uri instance that contains the address of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithExampleAddress( bool bypassLocal )
{
   return gcnew WebProxy( gcnew Uri( "http://contoso" ), bypassLocal );
}
public static WebProxy CreateProxyWithExampleAddress(bool bypassLocal)
{
    return new WebProxy(new Uri("http://contoso"), bypassLocal);
}

Remarks

The WebProxy instance is initialized with the Address property set to Address and with the BypassProxyOnLocal property set to BypassOnLocal.

Applies to

WebProxy(Uri, Boolean, String[], ICredentials)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(Uri ^ Address, bool BypassOnLocal, cli::array <System::String ^> ^ BypassList, System::Net::ICredentials ^ Credentials);
public WebProxy (Uri? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials);
public WebProxy (Uri Address, bool BypassOnLocal, string[] BypassList, System.Net.ICredentials Credentials);
new System.Net.WebProxy : Uri * bool * string[] * System.Net.ICredentials -> System.Net.WebProxy
Public Sub New (Address As Uri, BypassOnLocal As Boolean, BypassList As String(), Credentials As ICredentials)

Parameters

Address
Uri

A Uri instance that contains the address of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

BypassList
String[]

An array of regular expression strings that contains the URIs of the servers to bypass.

Credentials
ICredentials

An ICredentials instance to submit to the proxy server for authentication.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithCredentials2( bool bypassLocal )
{
   
   // Do not use the proxy server for Contoso.com URIs.
   array<String^>^ bypassList = {";*.Contoso.com"};
   return gcnew WebProxy( gcnew Uri( "http://contoso" ),
      bypassLocal,
      bypassList,
      CredentialCache::DefaultCredentials );
}
public static WebProxy CreateProxyWithCredentials2(bool bypassLocal)
{
    // Do not use the proxy server for Contoso.com URIs.
    string[] bypassList = new string[]{";*.Contoso.com"};
    return new WebProxy(new Uri("http://contoso"),
        bypassLocal,
        bypassList,
        CredentialCache.DefaultCredentials);
}

Remarks

The WebProxy instance is initialized with the Address property set to Address, the BypassProxyOnLocal property set to BypassOnLocal, the BypassList property set to BypassList, and the Credentials property set to Credentials.

Applies to

WebProxy(String, Boolean)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(System::String ^ Address, bool BypassOnLocal);
public WebProxy (string? Address, bool BypassOnLocal);
public WebProxy (string Address, bool BypassOnLocal);
new System.Net.WebProxy : string * bool -> System.Net.WebProxy
Public Sub New (Address As String, BypassOnLocal As Boolean)

Parameters

Address
String

The URI of the proxy server.

BypassOnLocal
Boolean

true to bypass the proxy for local addresses; otherwise, false.

Exceptions

Address is an invalid URI.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithHostAddress( bool bypassLocal )
{
   WebProxy^ proxy = gcnew WebProxy( "http://contoso",bypassLocal );
   Console::WriteLine( "Bypass proxy for local URIs?: {0}", 
      proxy->BypassProxyOnLocal );
   return proxy;
}
public static WebProxy CreateProxyWithHostAddress(bool bypassLocal)
{
    WebProxy proxy =  new WebProxy("http://contoso", bypassLocal);
    Console.WriteLine("Bypass proxy for local URIs?: {0}",
       proxy.BypassProxyOnLocal);
    return proxy;
}

Remarks

The WebProxy instance is initialized with the Address property set to a Uri instance that contains Address and the BypassProxyOnLocal property set to BypassOnLocal.

See also

Applies to

WebProxy(SerializationInfo, StreamingContext)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes an instance of the WebProxy class using previously serialized content.

protected:
 WebProxy(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected WebProxy (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WebProxy (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
new System.Net.WebProxy : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebProxy
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Net.WebProxy : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebProxy
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)

Parameters

serializationInfo
SerializationInfo

The serialization data.

streamingContext
StreamingContext

The context for the serialized data.

Attributes

Remarks

This method is called by the system to deserialize a WebProxy instance; applications do not call it.

Applies to

WebProxy(Uri)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

Initializes a new instance of the WebProxy class from the specified Uri instance.

public:
 WebProxy(Uri ^ Address);
public WebProxy (Uri? Address);
public WebProxy (Uri Address);
new System.Net.WebProxy : Uri -> System.Net.WebProxy
Public Sub New (Address As Uri)

Parameters

Address
Uri

A Uri instance that contains the address of the proxy server.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithExampleAddress()
{
   return gcnew WebProxy( gcnew Uri( "http://contoso" ) );
}
public static WebProxy CreateProxyWithExampleAddress()
{
    return new WebProxy(new Uri("http://contoso"));
}

Remarks

The WebProxy instance is initialized with the Address property set to the Address parameter.

Applies to

WebProxy(String)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

Initializes a new instance of the WebProxy class with the specified URI.

public:
 WebProxy(System::String ^ Address);
public WebProxy (string? Address);
public WebProxy (string Address);
new System.Net.WebProxy : string -> System.Net.WebProxy
Public Sub New (Address As String)

Parameters

Address
String

The URI of the proxy server.

Exceptions

Address is an invalid URI.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithHost()
{
   return gcnew WebProxy( "http://contoso" );
}
public static WebProxy CreateProxyWithHost()
{
    return new WebProxy("http://contoso");
}

Remarks

The WebProxy instance is initialized with the Address property set to a Uri instance containing Address.

Applies to

WebProxy(String, Int32)

Source:
WebProxy.cs
Source:
WebProxy.cs
Source:
WebProxy.cs

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

public:
 WebProxy(System::String ^ Host, int Port);
public WebProxy (string Host, int Port);
new System.Net.WebProxy : string * int -> System.Net.WebProxy
Public Sub New (Host As String, Port As Integer)

Parameters

Host
String

The name of the proxy host.

Port
Int32

The port number on Host to use.

Exceptions

The URI formed by combining Host and Port is not a valid URI.

Examples

The following code example demonstrates calling this constructor.

WebProxy^ CreateProxyWithHostAndPort()
{
   return gcnew WebProxy( "contoso",80 );
}
public static WebProxy CreateProxyWithHostAndPort()
{
    return new WebProxy("contoso", 80);
}

Remarks

The WebProxy instance is initialized with the Address property set to a Uri instance of the form http:// Host : Port.

Applies to