WebProxy 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
包含 HttpClient 類別的 HTTP Proxy 設定。
public ref class WebProxy : System::Net::IWebProxy, System::Runtime::Serialization::ISerializable
public ref class WebProxy : System::Runtime::Serialization::ISerializable
public class WebProxy : System.Net.IWebProxy, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class WebProxy : System.Net.IWebProxy, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class WebProxy : System.Runtime.Serialization.ISerializable
type WebProxy = class
interface IWebProxy
interface ISerializable
[<System.Serializable>]
type WebProxy = class
interface IWebProxy
interface ISerializable
[<System.Serializable>]
type WebProxy = class
interface ISerializable
interface IWebProxy
Public Class WebProxy
Implements ISerializable, IWebProxy
Public Class WebProxy
Implements ISerializable
- 繼承
-
WebProxy
- 屬性
- 實作
範例
下列程式碼範例會使用 實例來設定 HttpClient 實例 WebProxy 。 實例 HttpClient 會使用 Proxy 連線到外部網際網路資源。 (如需示範如何使用 WPAD 功能的範例,請參閱 IWebProxyScript class.)
WebProxy^ proxyObject = gcnew WebProxy("http://proxyserver:80/", true);
// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClientHandler^ handler = gcnew HttpClientHandler();
handler->Proxy = proxyObject;
HttpClient^ client = gcnew HttpClient(handler);
WebProxy proxyObject = new WebProxy("http://proxyserver:80/", true);
// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClient client = new HttpClient(new HttpClientHandler
{
Proxy = proxyObject
});
Dim proxyObject As New WebProxy("http://proxyserver:80/", True)
' HttpClient lifecycle management best practices:
' https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
Dim client As New HttpClient(New HttpClientHandler With
{
.Proxy = proxyObject
})
備註
類別 WebProxy 包含實例用來判斷 Web Proxy 是否用來傳送要求的 Proxy 設定 HttpClient 。 全域 Web Proxy 設定可以在電腦和應用程式組態檔中指定,而應用程式可以使用 類別的 WebProxy 實例來自訂 Web Proxy 使用。 類別 WebProxy 是 介面的基底實作 IWebProxy 。
若要取得 Web Proxy 類別的實例,您可以使用下列任何方法:
這些方法各提供您可以進一 WebProxy 步自訂的實例;它們之間的差異在於實例在傳回應用程式之前如何初始化實例。 建 WebProxy 構函式會傳回 類別的實例, AddressWebProxy 並將 屬性設定為 null
。 當要求使用此 WebProxy 狀態的實例時,不會使用 Proxy 來傳送要求。
方法會 GetDefaultProxy 傳回 類別的 AddressWebProxy 實例,並將 、 BypassProxyOnLocal 和 BypassList 屬性設定為 Internet Explorer 5.5 和更新版本所使用的值。
方法會 Select 傳回 類別的 WebProxy 實例,其屬性會根據 Internet Explorer 和組態檔設定的組合來設定。
類別支援 Proxy 組 WebProxy 態腳本的自動偵測和執行。 這項功能也稱為「Web Proxy 自動探索 (WPAD)」。 使用自動 Proxy 設定時,通常名為 Wpad.dat 的設定腳本必須位於、下載、編譯和執行。 如果這些作業成功,腳本會傳回可用於要求的 Proxy。
建構函式
WebProxy() |
初始化 WebProxy 類別的空執行個體。 |
WebProxy(SerializationInfo, StreamingContext) |
使用先前序列化的內容,初始化 WebProxy 類別的執行個體。 |
WebProxy(String) |
使用指定的 URI,初始化 WebProxy 類別的新執行個體。 |
WebProxy(String, Boolean) |
使用指定 URI 和略過設定,初始化 WebProxy 類別的新執行個體。 |
WebProxy(String, Boolean, String[]) |
使用指定位址、略過設定和要略過的 URI 清單,初始化 WebProxy 類別的新執行個體。 |
WebProxy(String, Boolean, String[], ICredentials) |
使用指定 URI、略過設定、要略過的 URI 清單和認證,初始化 WebProxy 類別的新執行個體。 |
WebProxy(String, Int32) |
使用指定主機和連接埠編號,初始化 WebProxy 類別的新執行個體。 |
WebProxy(Uri) | |
WebProxy(Uri, Boolean) | |
WebProxy(Uri, Boolean, String[]) | |
WebProxy(Uri, Boolean, String[], ICredentials) |
屬性
Address |
取得或設定 Proxy 伺服器的位址。 |
BypassArrayList |
取得不使用 Proxy 伺服器的位址清單。 |
BypassList |
取得或設定不使用 Proxy 伺服器的位址陣列。 |
BypassProxyOnLocal |
取得或設定值,這個值表示是否略過 Proxy 伺服器而改用本機位址。 |
Credentials |
取得或設定認證,提交到 Proxy 伺服器進行驗證。 |
UseDefaultCredentials |
取得或設定 Boolean 值,控制是否隨著要求傳送 DefaultCredentials。 |
方法
CreateDefaultProxy() |
包含 HttpClient 類別的 HTTP Proxy 設定。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetDefaultProxy() |
已淘汰.
已淘汰.
已淘汰.
讀取 Internet Explorer 非動態 Proxy 設定。 |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetObjectData(SerializationInfo, StreamingContext) |
將序列化目標物件所需的資料填入 SerializationInfo。 |
GetProxy(Uri) |
傳回要求的代理 URI。 |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
IsBypassed(Uri) |
指示是否要為指定主機使用 Proxy 伺服器。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
明確介面實作
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
建立系統用來序列化 WebProxy 物件的序列化資料和內容。 |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應