HttpVersion 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義 HttpWebRequest 和 HttpWebResponse 類別 (Class) 支援的 HTTP 版本號碼。
public ref class HttpVersion abstract sealed
public ref class HttpVersion
public static class HttpVersion
public class HttpVersion
type HttpVersion = class
Public Class HttpVersion
- 繼承
-
HttpVersion
範例
下列範例示範 HttpVersion 的用法。
// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
HttpClient^ client = gcnew HttpClient();
HttpRequestMessage^ request = new HttpRequestMessage(HttpMethod::Get, "http://www.microsoft.com");
Console::WriteLine("Default HTTP request version is {0}", request.Version);
request.Version = HttpVersion.Version10;
Console::WriteLine("Request version after assignment is {0}", request.Version);
HttpResponseMessage^ response = client->Send(request);
Console::WriteLine("Response HTTP version {0}", response.Version);
// HttpClient lifecycle management best practices:
// https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
using HttpClient client = new HttpClient();
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com");
Console.WriteLine("Default HTTP request version is {0}", request.Version);
request.Version = HttpVersion.Version10;
Console.WriteLine("Request version after assignment is {0}", request.Version);
using HttpResponseMessage response = client.Send(request);
Console.WriteLine("Response HTTP version {0}", response.Version);
' HttpClient lifecycle management best practices:
' https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use
Using client As New HttpClient()
Using request As New HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com")
Console.WriteLine("Default HTTP request version is {0}", request.Version)
request.Version = HttpVersion.Version10
Console.WriteLine("Request version after assignment is {0}", request.Version)
Using response As HttpResponseMessage = client.Send(request)
Console.WriteLine("Response HTTP version {0}", response.Version)
End Using
End Using
End Using
備註
類別 HttpVersion 會定義 類別所 HttpClient 支援的 HTTP 版本。 HTTP 版本號碼是用來控制 HTTP 的版本特定功能,例如管線和區塊化。
建構函式
HttpVersion() |
初始化 HttpVersion 類別的新執行個體。 |
欄位
Unknown |
定義未知 HTTP 版本的 Version 執行個體。 |
Version10 |
定義 HTTP 1.0 的 Version 執行個體。 |
Version11 |
定義 HTTP 1.1 的 Version 執行個體。 |
Version20 |
定義 HTTP 2.0 的 Version 執行個體。 |
Version30 |
定義 Version HTTP 3.0 的實例。 |