HttpVersion Classe

Definição

Define os números de versão HTTP aos quais as classes HttpWebRequest e HttpWebResponse dão suporte.

public ref class HttpVersion abstract sealed
public ref class HttpVersion
public static class HttpVersion
public class HttpVersion
type HttpVersion = class
Public Class HttpVersion
Herança
HttpVersion

Exemplos

O exemplo a seguir demonstra o uso de 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

Comentários

A HttpVersion classe define as versões HTTP compatíveis com a HttpClient classe . O número da versão HTTP é usado para controlar recursos específicos da versão do HTTP, como pipelining e agrupamento.

Construtores

HttpVersion()

Inicializa uma nova instância da classe HttpVersion.

Campos

Unknown

Define uma instância Version para uma versão HTTP desconhecida.

Version10

Define uma instância Version para o HTTP 1.0.

Version11

Define uma instância Version para o HTTP 1.1.

Version20

Define uma instância Version para o HTTP 2.0.

Version30

Define uma Version instância para HTTP 3.0.

Aplica-se a