PROPERTY

HttpRequestMessage.VersionPolicy

Controls how the requested HTTP version may be negotiated. Setting this property is not evidence that a specific HTTP version was used; inspect the actual response version.

Formal Syntax & Structure

csharp syntaxcsharp
request.VersionPolicy = HttpVersionPolicy.RequestVersionOrLower;

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Threading;using var request = new HttpRequestMessage(HttpMethod.Get,"https://example.invalid/");request.Version = HttpVersion.Version20;request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;Console.WriteLine(request.VersionPolicy); // RequestVersionExact
C# & .NET Reference