Udostępnij za pośrednictwem


HttpVersion Klasa

Definicja

Definiuje numery wersji PROTOKOŁU HTTP obsługiwane przez HttpWebRequest klasy i HttpWebResponse .

public ref class HttpVersion abstract sealed
public ref class HttpVersion
public static class HttpVersion
public class HttpVersion
type HttpVersion = class
Public Class HttpVersion
Dziedziczenie
HttpVersion

Przykłady

W poniższym przykładzie pokazano użycie polecenia 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

Uwagi

Klasa HttpVersion definiuje wersje HTTP obsługiwane przez klasę HttpClient . Numer wersji HTTP służy do kontrolowania funkcji specyficznych dla wersji protokołu HTTP, takich jak potokowanie i fragmentowanie.

Konstruktory

HttpVersion()

Inicjuje nowe wystąpienie klasy HttpVersion.

Pola

Unknown

Version Definiuje wystąpienie nieznanej wersji protokołu HTTP.

Version10

Version Definiuje wystąpienie protokołu HTTP 1.0.

Version11

Version Definiuje wystąpienie protokołu HTTP 1.1.

Version20

Version Definiuje wystąpienie protokołu HTTP 2.0.

Version30

Version Definiuje wystąpienie protokołu HTTP 3.0.

Dotyczy