WebProxy 构造函数
定义
重载
| WebProxy() |
初始化 WebProxy 类的空实例。Initializes an empty instance of the WebProxy class. |
| WebProxy(String) |
用指定的 URI 初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI. |
| WebProxy(Uri) |
从指定的 WebProxy 实例中初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class from the specified Uri instance. |
| WebProxy(SerializationInfo, StreamingContext) |
使用以前序列化的内容初始化 WebProxy 类的实例。Initializes an instance of the WebProxy class using previously serialized content. |
| WebProxy(String, Boolean) |
使用指定的 URI 和回避设置初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI and bypass setting. |
| WebProxy(String, Int32) |
使用指定的主机和端口号初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified host and port number. |
| WebProxy(Uri, Boolean) |
使用 WebProxy 实例和回避设置初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class with the Uri instance and bypass setting. |
| WebProxy(String, Boolean, String[]) |
使用指定的 URI、回避设置和要回避的 URI 列表初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass. |
| WebProxy(Uri, Boolean, String[]) |
使用指定的 WebProxy 实例、回避设置和要回避的 URI 列表初始化 Uri 类的新实例。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[], ICredentials) |
使用指定的 URI、回避设置、要回避的 URI 列表和凭据初始化 WebProxy 类的新实例。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[], ICredentials) |
使用指定的 WebProxy 实例、回避设置、要回避的 URI 列表和凭据初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class with the specified Uri instance, bypass setting, list of URIs to bypass, and credentials. |
WebProxy()
public:
WebProxy();
public WebProxy ();
Public Sub New ()
示例
下面的代码示例演示如何调用此构造函数。The following code example demonstrates calling this constructor.
WebProxy^ CreateProxy()
{
return gcnew WebProxy;
}
public static WebProxy CreateProxy()
{
return new WebProxy();
}
注解
无参数构造函数初始化类的空实例 WebProxy ,并将 Address 属性设置为 null 。The parameterless constructor initializes an empty instance of the WebProxy class with the Address property set to null.
当 Address 属性为时 null , IsBypassed 方法将返回, true 并且 GetProxy 方法将返回目标地址。When the Address property is null, the IsBypassed method returns true and the GetProxy method returns the destination address.
适用于
WebProxy(String)
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。The URI of the proxy server.
例外
Address 是无效的 URI。Address is an invalid URI.
示例
下面的代码示例演示如何调用此构造函数。The following code example demonstrates calling this constructor.
WebProxy^ CreateProxyWithHost()
{
return gcnew WebProxy( "http://contoso" );
}
public static WebProxy CreateProxyWithHost()
{
return new WebProxy("http://contoso");
}
注解
WebProxy初始化实例,并将 Address 属性设置为包含的 Uri 实例 Address 。The WebProxy instance is initialized with the Address property set to a Uri instance containing Address.
适用于
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)
参数
示例
下面的代码示例演示如何调用此构造函数。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"));
}
注解
WebProxy初始化实例,并将 Address 属性设置为 Address 参数。The WebProxy instance is initialized with the Address property set to the Address parameter.
适用于
WebProxy(SerializationInfo, StreamingContext)
protected:
WebProxy(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
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
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)
参数
- serializationInfo
- SerializationInfo
序列化数据。The serialization data.
- streamingContext
- StreamingContext
序列化数据的上下文。The context for the serialized data.
注解
系统调用此方法对实例进行反序列化 WebProxy ; 应用程序不调用它。This method is called by the system to deserialize a WebProxy instance; applications do not call it.
适用于
WebProxy(String, Boolean)
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。The URI of the proxy server.
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
例外
Address 是无效的 URI。Address is an invalid URI.
示例
下面的代码示例演示如何调用此构造函数。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;
}
注解
初始化实例,并将 WebProxy Address 属性设置为包含的 Uri 实例 Address ,并将 BypassProxyOnLocal 属性设置为 BypassOnLocal 。The WebProxy instance is initialized with the Address property set to a Uri instance that contains Address and the BypassProxyOnLocal property set to BypassOnLocal.
另请参阅
适用于
WebProxy(String, Int32)
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
代理主机的名称。The name of the proxy host.
- Port
- Int32
要使用的 Host 上的端口号。The port number on Host to use.
例外
通过组合 Host 和 Port 构成的 URI 不是有效的 URI。The URI formed by combining Host and Port is not a valid URI.
示例
下面的代码示例演示如何调用此构造函数。The following code example demonstrates calling this constructor.
WebProxy^ CreateProxyWithHostAndPort()
{
return gcnew WebProxy( "contoso",80 );
}
public static WebProxy CreateProxyWithHostAndPort()
{
return new WebProxy("contoso", 80);
}
注解
WebProxy初始化实例,并将 Address 属性设置为 Uri http://:的实例 Host Port 。The WebProxy instance is initialized with the Address property set to a Uri instance of the form http:// Host : Port.
适用于
WebProxy(Uri, Boolean)
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)
参数
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
示例
下面的代码示例演示如何调用此构造函数。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);
}
注解
WebProxy初始化实例, Address 并将属性设置为 Address ,并将 BypassProxyOnLocal 属性设置为 BypassOnLocal 。The WebProxy instance is initialized with the Address property set to Address and with the BypassProxyOnLocal property set to BypassOnLocal.
适用于
WebProxy(String, Boolean, String[])
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。The URI of the proxy server.
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
- BypassList
- String[]
一个正则表达式字符串数组,它包含要跳过的服务器的 URI。An array of regular expression strings that contain the URIs of the servers to bypass.
例外
Address 是无效的 URI。Address is an invalid URI.
示例
下面的代码示例演示如何调用此构造函数。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);
}
注解
WebProxy初始化实例,并将 Address 属性设置为包含的 Uri 实例,将 Address 属性设置 BypassProxyOnLocal 为 BypassOnLocal ,并将 BypassList 属性设置为 BypassList 。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.
另请参阅
适用于
WebProxy(Uri, Boolean, String[])
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())
参数
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
- BypassList
- String[]
一个正则表达式字符串数组,它包含要跳过的服务器的 URI。An array of regular expression strings that contains the URIs of the servers to bypass.
示例
下面的代码示例演示如何调用此构造函数。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);
}
注解
WebProxy初始化实例,并将 Address 属性设置为,并将属性设置为 Address BypassProxyOnLocal BypassOnLocal ,并将 BypassList 属性设置为 BypassList 。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.
适用于
WebProxy(String, Boolean, String[], ICredentials)
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。The URI of the proxy server.
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
- BypassList
- String[]
一个正则表达式字符串数组,它包含要跳过的服务器的 URI。An array of regular expression strings that contains the URIs of the servers to bypass.
- Credentials
- ICredentials
要提交给代理服务器进行身份验证的 ICredentials 实例。An ICredentials instance to submit to the proxy server for authentication.
例外
Address 是无效的 URI。Address is an invalid URI.
示例
下面的代码示例演示如何调用此构造函数。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);
}
注解
WebProxy初始化实例,并将 Address 属性设置为包含的 Uri 实例,将 Address 属性设置为,属性设置 BypassProxyOnLocal BypassOnLocal BypassList 为 BypassList ,并将 Credentials 属性设置为 Credentials 。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.
另请参阅
适用于
WebProxy(Uri, Boolean, String[], ICredentials)
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)
参数
- BypassOnLocal
- Boolean
如果对本地地址跳过代理,则为 true;否则,为 false。true to bypass the proxy for local addresses; otherwise, false.
- BypassList
- String[]
一个正则表达式字符串数组,它包含要跳过的服务器的 URI。An array of regular expression strings that contains the URIs of the servers to bypass.
- Credentials
- ICredentials
要提交给代理服务器进行身份验证的 ICredentials 实例。An ICredentials instance to submit to the proxy server for authentication.
示例
下面的代码示例演示如何调用此构造函数。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);
}
注解
WebProxy初始化实例时 Address ,属性设置为,属性 Address 设置为, BypassProxyOnLocal BypassOnLocal BypassList 属性设置为 BypassList , Credentials 属性设置为 Credentials 。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.