HttpVersion 类

定义

定义 HttpWebRequestHttpWebResponse 类支持的 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 的 实例。

适用于