WebProxy 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 WebProxy 類別的新執行個體。
多載
WebProxy() |
初始化 WebProxy 類別的空執行個體。 |
WebProxy(String, Boolean, String[], ICredentials) |
使用指定 URI、略過設定、要略過的 URI 清單和認證,初始化 WebProxy 類別的新執行個體。 |
WebProxy(Uri, Boolean, String[]) | |
WebProxy(String, Boolean, String[]) |
使用指定位址、略過設定和要略過的 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()
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
初始化 WebProxy 類別的空執行個體。
public:
WebProxy();
public WebProxy ();
Public Sub New ()
範例
下列程式代碼範例示範如何呼叫這個建構函式。
WebProxy^ CreateProxy()
{
return gcnew WebProxy;
}
public static WebProxy CreateProxy()
{
return new WebProxy();
}
備註
沒有參數建構函式會初始化 類別的空白實例,WebProxyAddress並將屬性設定為 null
。
Address當 屬性為 null
時,方法IsBypassed會傳true
回 ,而 GetProxy 方法會傳回目的地位址。
適用於
WebProxy(String, Boolean, String[], ICredentials)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
Proxy 伺服器的 URI。
- BypassOnLocal
- Boolean
若要近端網址不使用 Proxy,則為 true
,否則為 false
。
- BypassList
- String[]
規則運算式字串的陣列,其中包含要略過的伺服器 URI。
- Credentials
- ICredentials
ICredentials 執行個體,要送出至 Proxy 伺服器進行驗證。
例外狀況
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
、屬性設定為 BypassOnLocal
、BypassListBypassProxyOnLocal屬性設定為 BypassList
,並將 Credentials 屬性設定為 Credentials
。
另請參閱
適用於
WebProxy(Uri, Boolean, String[])
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
若要近端網址不使用 Proxy,則為 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並將屬性設定為 Address
、BypassProxyOnLocal屬性設定為 BypassOnLocal
,並將 BypassList 屬性設定為 BypassList
。
適用於
WebProxy(String, Boolean, String[])
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
使用指定位址、略過設定和要略過的 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
Proxy 伺服器的 URI。
- BypassOnLocal
- Boolean
若要近端網址不使用 Proxy,則為 true
,否則為 false
。
- BypassList
- String[]
規則運算式 (Regular Expression) 字串的陣列,包含要略過的伺服器 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 屬性設定為 BypassOnLocal
,並將 BypassList 屬性設定為 BypassList
。
另請參閱
適用於
WebProxy(Uri, Boolean)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
若要近端網址不使用 Proxy,則為 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並將屬性設定Address
為 ,並將 BypassProxyOnLocal 屬性設定為 BypassOnLocal
。
適用於
WebProxy(Uri, Boolean, String[], ICredentials)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
若要近端網址不使用 Proxy,則為 true
,否則為 false
。
- BypassList
- String[]
規則運算式字串的陣列,其中包含要略過的伺服器 URI。
- Credentials
- ICredentials
ICredentials 執行個體,要送出至 Proxy 伺服器進行驗證。
範例
下列程式代碼範例示範如何呼叫這個建構函式。
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
。
適用於
WebProxy(String, Boolean)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
Proxy 伺服器的 URI。
- BypassOnLocal
- Boolean
若要近端網址不使用 Proxy,則為 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)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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)
參數
範例
下列程式代碼範例示範如何呼叫這個建構函式。
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)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
Proxy 伺服器的 URI。
例外狀況
Address
為無效的 URI。
範例
下列程式代碼範例示範如何呼叫這個建構函式。
WebProxy^ CreateProxyWithHost()
{
return gcnew WebProxy( "http://contoso" );
}
public static WebProxy CreateProxyWithHost()
{
return new WebProxy("http://contoso");
}
備註
實例 WebProxy 會初始化, Address 並將屬性設定為 Uri 包含 Address
的實例。
適用於
WebProxy(String, Int32)
- 來源:
- WebProxy.cs
- 來源:
- WebProxy.cs
- 來源:
- 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
Proxy 主機名稱。
- Port
- Int32
要在 Host
上使用的連接埠編號。
例外狀況
結合 Host
和 Port
所形成的 URI 不是有效的 URI。
範例
下列程式代碼範例示範如何呼叫這個建構函式。
WebProxy^ CreateProxyWithHostAndPort()
{
return gcnew WebProxy( "contoso",80 );
}
public static WebProxy CreateProxyWithHostAndPort()
{
return new WebProxy("contoso", 80);
}
備註
WebProxy實體會初始化,Address並將屬性設定為Uri表單的實體,http:// Host
: Port
。