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.

C#
public WebProxy();

Examples

The following code example demonstrates calling this constructor.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials);
C#
public WebProxy(string Address, bool BypassOnLocal, string[] BypassList, System.Net.ICredentials Credentials);

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

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

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

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

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public WebProxy(Uri? Address, bool BypassOnLocal);
C#
public WebProxy(Uri Address, bool BypassOnLocal);

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials);
C#
public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList, System.Net.ICredentials Credentials);

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public WebProxy(string? Address, bool BypassOnLocal);
C#
public WebProxy(string Address, bool BypassOnLocal);

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
[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);
C#
protected WebProxy(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext 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

.NET 10 i druge verzije
Proizvod Verzije (Zastarjelo)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

WebProxy(Uri)

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

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

C#
public WebProxy(Uri? Address);
C#
public WebProxy(Uri Address);

Parameters

Address
Uri

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

Examples

The following code example demonstrates calling this constructor.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

WebProxy(String)

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

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

C#
public WebProxy(string? Address);
C#
public WebProxy(string Address);

Parameters

Address
String

The URI of the proxy server.

Exceptions

Address is an invalid URI.

Examples

The following code example demonstrates calling this constructor.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public WebProxy(string Host, int Port);

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.

C#
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1