WebProxy 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 WebProxy 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| WebProxy() |
初始化类的 WebProxy 空实例。 |
| WebProxy(String, Boolean, String[], ICredentials) |
使用指定的 URI、绕过设置、要绕过的 URI 列表和凭据初始化类的新实例 WebProxy 。 |
| WebProxy(Uri, Boolean, String[]) | |
| WebProxy(String, Boolean, String[]) |
使用指定的 URI、绕过设置和要绕过的 URI 列表初始化类的新实例 WebProxy 。 |
| WebProxy(Uri, Boolean) | |
| WebProxy(Uri, Boolean, String[], ICredentials) | |
| WebProxy(String, Boolean) |
使用指定的 URI 和绕过设置初始化类的新实例 WebProxy 。 |
| WebProxy(SerializationInfo, StreamingContext) |
已过时.
使用以前序列化的内容初始化类的 WebProxy 实例。 |
| WebProxy(Uri) | |
| WebProxy(String) |
使用指定的 URI 初始化类的新实例 WebProxy 。 |
| WebProxy(String, Int32) |
使用指定的主机和端口号初始化类的新实例 WebProxy 。 |
WebProxy()
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
初始化类的 WebProxy 空实例。
public:
WebProxy();
public WebProxy();
Public Sub New ()
示例
下面的代码示例演示如何调用此构造函数。
public static WebProxy CreateProxy()
{
return new WebProxy();
}
注解
无参数构造函数使用属性设置为 <
Address当属性为null时,IsBypassed该方法返回true,该方法GetProxy返回目标地址。
适用于
WebProxy(String, Boolean, String[], ICredentials)
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- 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。
示例
下面的代码示例演示如何调用此构造函数。
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该实例。
另请参阅
适用于
WebProxy(Uri, Boolean, String[])
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
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.
- BypassList
- String[]
包含要绕过的服务器 URI 的正则表达式字符串数组。
示例
下面的代码示例演示如何调用此构造函数。
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(String, Boolean, String[])
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- 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。
示例
下面的代码示例演示如何调用此构造函数。
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
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
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.
示例
下面的代码示例演示如何调用此构造函数。
public static WebProxy CreateProxyWithExampleAddress(bool bypassLocal)
{
return new WebProxy(new Uri("http://contoso"), bypassLocal);
}
注解
实例初始化时,属性
适用于
WebProxy(Uri, Boolean, String[], ICredentials)
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
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.
- BypassList
- String[]
包含要绕过的服务器 URI 的正则表达式字符串数组。
- Credentials
- ICredentials
ICredentials要提交到代理服务器进行身份验证的实例。
示例
下面的代码示例演示如何调用此构造函数。
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、BypassProxyOnLocal属性设置为BypassOnLocal、BypassList属性设置为BypassList和Credentials属性设置为 Credentials。Address
适用于
WebProxy(String, Boolean)
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- 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。
示例
下面的代码示例演示如何调用此构造函数。
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和属性设置为的BypassProxyOnLocalBypassOnLocal实例。
另请参阅
适用于
WebProxy(SerializationInfo, StreamingContext)
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- 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);
[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);
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}")>]
new System.Net.WebProxy : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebProxy
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
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
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)
参数
示例
下面的代码示例演示如何调用此构造函数。
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
- 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。
示例
下面的代码示例演示如何调用此构造函数。
public static WebProxy CreateProxyWithHost()
{
return new WebProxy("http://contoso");
}
注解
使用WebProxy属性设置为包含Address的Uri实例初始化Address实例。
适用于
WebProxy(String, Int32)
- Source:
- WebProxy.cs
- Source:
- WebProxy.cs
- 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 。
例外
通过组合 Host 形成的 URI, Port 不是有效的 URI。
示例
下面的代码示例演示如何调用此构造函数。
public static WebProxy CreateProxyWithHostAndPort()
{
return new WebProxy("contoso", 80);
}
注解
实例初始化时,该WebProxy属性设置为窗体的实例 Uri http:// Host : Port。Address