WebProxy 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
包含該 HttpClient 類別的 HTTP 代理設定。
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
Public Class WebProxy
Implements ISerializable, IWebProxy
Public Class WebProxy
Implements ISerializable
- 繼承
-
WebProxy
- 屬性
- 實作
範例
以下範例用實例建立 HttpClient 一個實 WebProxy 例。 該 HttpClient 實例使用代理伺服器連接外部網際網路資源。 (有關使用 WPAD 功能的範例,請參閱該 IWebProxyScript 類別的文件。)
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 類別包含代理設定,實 HttpClient 例用來判斷是否使用網頁代理來發送請求。 全域網頁代理設定可在機器與應用程式設定檔中指定,應用程式也可利用該 WebProxy 類別的實例來自訂網頁代理的使用。 這個 WebProxy 類別是介面的 IWebProxy 基礎實作。
要取得 Web 代理類別的實例,您可以使用以下任一種方法:
- 建造者 WebProxy 。
- GetDefaultProxy 方法。
- Select 方法。
這些方法各自提供 WebProxy 一個你可以進一步自訂的實例;它們的差別在於實例在回傳到你的應用程式之前,是如何初始化的。
WebProxy建構子回傳一個類別的實例WebProxy,屬性Address設為 null。 當請求使用 WebProxy 處於此狀態的實例時,不會使用代理伺服器來傳送請求。
該GetDefaultProxy方法回傳一個類別的實例WebProxy,其 、 AddressBypassProxyOnLocal、 BypassList ,屬性設定為本地電腦使用的值。
該 Select 方法回傳一個類別實例 WebProxy ,其屬性依據網際網路與配置檔設定組合而設。
此 WebProxy 類別支援代理設定腳本的自動偵測與執行。 此功能也稱為網頁代理自動發現(WPAD)。 使用自動代理設定時,必須找到一個通常稱為 Wpad.dat 的設定腳本,下載、編譯並執行。 若這些操作成功,腳本會回傳可用於請求的代理。
建構函式
| 名稱 | Description |
|---|---|
| WebProxy() |
初始化類別的 WebProxy 空實例。 |
| WebProxy(SerializationInfo, StreamingContext) |
已淘汰.
利用先前序列化的內容初始化類別實 WebProxy 例。 |
| WebProxy(String, Boolean, String[], ICredentials) |
初始化一個新實例 WebProxy ,使用指定的 URI、繞過設定、可繞過的 URI 清單及憑證。 |
| WebProxy(String, Boolean, String[]) |
初始化一個新的類別實例 WebProxy ,並設定指定的 URI、繞過設定及可繞過的 URI 清單。 |
| WebProxy(String, Boolean) |
初始化一個新的類別實例 WebProxy ,並使用指定的 URI 與繞過設定。 |
| WebProxy(String, Int32) |
初始化一個以指定主機與埠號的新類別實例 WebProxy 。 |
| WebProxy(String) |
初始化一個新的類別實例 WebProxy ,使用指定的 URI。 |
| WebProxy(Uri, Boolean, String[], ICredentials) | |
| WebProxy(Uri, Boolean, String[]) | |
| WebProxy(Uri, Boolean) | |
| WebProxy(Uri) |
屬性
| 名稱 | Description |
|---|---|
| Address |
取得或設定代理伺服器的位址。 |
| BypassArrayList |
會取得一份不使用代理伺服器的位址清單。 |
| BypassList |
取得或設定一個不使用代理伺服器的位址陣列。 |
| BypassProxyOnLocal |
取得或設定一個值,指示是否繞過代理伺服器取得本地位址。 |
| Credentials |
取得或設定憑證提交給代理伺服器進行驗證。 |
| UseDefaultCredentials |
取得或設定一個 Boolean 值,控制是否 DefaultCredentials 會隨請求一起傳送。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetDefaultProxy() |
已淘汰.
已淘汰.
已淘汰.
讀取網路選項的非動態代理設定。 |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
在 a SerializationInfo 中填入序列化目標物件所需的資料。 |
| GetProxy(Uri) |
回傳代理的 URI 以回應請求。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsBypassed(Uri) |
指示是否要為指定主機使用代理伺服器。 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
建立序列化資料與上下文,供系統用來序列化物件 WebProxy 。 |