HttpVersion Třída

Definice

Definuje čísla verzí HTTP, které jsou podporovány třídami HttpWebRequest a HttpWebResponse .

public ref class HttpVersion abstract sealed
public ref class HttpVersion
public static class HttpVersion
public class HttpVersion
type HttpVersion = class
Public Class HttpVersion
Dědičnost
HttpVersion

Příklady

Následující příklad ukazuje použití .HttpVersion

// HttpClient lifecycle management best practices:
// https://video2.skills-academy.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://video2.skills-academy.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://video2.skills-academy.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

Poznámky

Třída HttpVersion definuje verze HTTP, které jsou podporovány HttpClient třídou. Číslo verze PROTOKOLU HTTP se používá k řízení funkcí http specifických pro konkrétní verze, jako je směrování a vytváření bloků dat.

Konstruktory

HttpVersion()

Inicializuje novou instanci HttpVersion třídy.

Pole

Unknown

Definuje Version instanci pro neznámou verzi PROTOKOLU HTTP.

Version10

Definuje Version instanci pro HTTP 1.0.

Version11

Definuje Version instanci pro HTTP 1.1.

Version20

Definuje Version instanci pro HTTP 2.0.

Version30

Definuje Version instanci pro HTTP 3.0.

Platí pro