WebProxy 构造函数

定义

初始化 WebProxy 类的新实例。

重载

WebProxy()

初始化 WebProxy 类的空实例。

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

使用指定的 URI、回避设置、要回避的 URI 列表和凭据初始化 WebProxy 类的新实例。

WebProxy(Uri, Boolean, String[])

使用指定的 WebProxy 实例、回避设置和要回避的 URI 列表初始化 Uri 类的新实例。

WebProxy(String, Boolean, String[])

使用指定的 URI、回避设置和要回避的 URI 列表初始化 WebProxy 类的新实例。

WebProxy(Uri, Boolean)

使用 WebProxy 实例和回避设置初始化 Uri 类的新实例。

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

使用指定的 WebProxy 实例、回避设置、要回避的 URI 列表和凭据初始化 Uri 类的新实例。

WebProxy(String, Boolean)

使用指定的 URI 和回避设置初始化 WebProxy 类的新实例。

WebProxy(SerializationInfo, StreamingContext)
已过时.

使用以前序列化的内容初始化 WebProxy 类的实例。

WebProxy(Uri)

从指定的 WebProxy 实例中初始化 Uri 类的新实例。

WebProxy(String)

用指定的 URI 初始化 WebProxy 类的新实例。

WebProxy(String, Int32)

使用指定的主机和端口号初始化 WebProxy 类的新实例。

WebProxy()

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

初始化 WebProxy 类的空实例。

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

示例

下面的代码示例演示如何调用此构造函数。

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

注解

无参数构造函数初始化 类的 WebProxy 空实例, Address 并将 属性设置为 null

Address当 属性为 null时,方法IsBypassed返回 trueGetProxy方法返回目标地址。

适用于

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

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

使用指定的 URI、回避设置、要回避的 URI 列表和凭据初始化 WebProxy 类的新实例。

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)

参数

Address
String

代理服务器的 URI。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

BypassList
String[]

一个正则表达式字符串数组,它包含要跳过的服务器的 URI。

Credentials
ICredentials

要提交给代理服务器进行身份验证的 ICredentials 实例。

例外

Address 是无效的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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);
}

注解

实例 WebProxy 初始化时, Address 属性设置为 Uri 包含 Address的实例, BypassProxyOnLocal 属性设置为 BypassOnLocalBypassList 属性设置为 BypassList,属性设置为 , Credentials 属性设置为 Credentials

另请参阅

适用于

WebProxy(Uri, Boolean, String[])

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

使用指定的 WebProxy 实例、回避设置和要回避的 URI 列表初始化 Uri 类的新实例。

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())

参数

Address
Uri

一个 Uri 实例,它包含代理服务器的地址。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

BypassList
String[]

一个正则表达式字符串数组,它包含要跳过的服务器的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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);
}

注解

实例 WebProxy 初始化时, Address 属性设置为 AddressBypassProxyOnLocal 属性设置为 BypassOnLocalBypassList 属性设置为 BypassList

适用于

WebProxy(String, Boolean, String[])

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

使用指定的 URI、回避设置和要回避的 URI 列表初始化 WebProxy 类的新实例。

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())

参数

Address
String

代理服务器的 URI。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

BypassList
String[]

一个正则表达式字符串数组,它包含要跳过的服务器的 URI。

例外

Address 是无效的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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);
}

注解

实例 WebProxy 初始化时, Address 属性设置为 Uri 包含 Address的实例 , BypassProxyOnLocal 属性设置为 BypassOnLocalBypassList 属性设置为 BypassList

另请参阅

适用于

WebProxy(Uri, Boolean)

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

使用 WebProxy 实例和回避设置初始化 Uri 类的新实例。

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)

参数

Address
Uri

一个 Uri 实例,它包含代理服务器的地址。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

示例

下面的代码示例演示如何调用此构造函数。

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);
}

注解

实例 WebProxy 初始化时, Address 属性设置为 AddressBypassProxyOnLocal 属性设置为 BypassOnLocal

适用于

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

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

使用指定的 WebProxy 实例、回避设置、要回避的 URI 列表和凭据初始化 Uri 类的新实例。

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)

参数

Address
Uri

一个 Uri 实例,它包含代理服务器的地址。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

BypassList
String[]

一个正则表达式字符串数组,它包含要跳过的服务器的 URI。

Credentials
ICredentials

要提交给代理服务器进行身份验证的 ICredentials 实例。

示例

下面的代码示例演示如何调用此构造函数。

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);
}

注解

实例 WebProxy 初始化时 Address ,属性设置为 AddressBypassProxyOnLocal 属性设置为 BypassOnLocalBypassList 属性设置为 BypassListCredentials 属性设置为 Credentials

适用于

WebProxy(String, Boolean)

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

使用指定的 URI 和回避设置初始化 WebProxy 类的新实例。

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)

参数

Address
String

代理服务器的 URI。

BypassOnLocal
Boolean

如果对本地地址跳过代理,则为 true;否则,为 false

例外

Address 是无效的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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;
}

注解

实例 WebProxy 初始化时, Address 属性设置为 Uri 包含 的 Address 实例,并将 BypassProxyOnLocal 属性设置为 BypassOnLocal

另请参阅

适用于

WebProxy(SerializationInfo, StreamingContext)

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

注意

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

使用以前序列化的内容初始化 WebProxy 类的实例。

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)

参数

serializationInfo
SerializationInfo

序列化数据。

streamingContext
StreamingContext

序列化数据的上下文。

属性

注解

系统调用此方法以反序列化 WebProxy 实例;应用程序不调用它。

适用于

WebProxy(Uri)

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

从指定的 WebProxy 实例中初始化 Uri 类的新实例。

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)

参数

Address
Uri

一个 Uri 实例,它包含代理服务器的地址。

示例

下面的代码示例演示如何调用此构造函数。

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

注解

实例 WebProxy 使用 Address 属性设置为 Address 参数进行初始化。

适用于

WebProxy(String)

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

用指定的 URI 初始化 WebProxy 类的新实例。

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)

参数

Address
String

代理服务器的 URI。

例外

Address 是无效的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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

注解

实例WebProxy初始化时,Address属性设置为包含 AddressUri实例。

适用于

WebProxy(String, Int32)

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

使用指定的主机和端口号初始化 WebProxy 类的新实例。

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)

参数

Host
String

代理主机的名称。

Port
Int32

要使用的 Host 上的端口号。

例外

通过组合 HostPort 构成的 URI 不是有效的 URI。

示例

下面的代码示例演示如何调用此构造函数。

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

注解

实例 WebProxy 初始化时, Address 属性设置为 Uri http:// Host 形式的实例: Port

适用于