0

I'm creating a sample C# environment for http3 in .net 6 I'm following this blog but I'm unable to make http/3 connection and getting this error:

System.Net.Http.HttpRequestException: 'Requesting HTTP version 3.0 with version policy RequestVersionExact while unable to establish HTTP/3 connection.'

I have put client and server projects seperately server project runs fine but client project gives this error and when i changed to "HttpVersion.Version20" it works fine.

Here is my Client Program.cs code

using System.Net;

// Create a handler to turn off SSL validation
//var EndPoint = "https://192.168.0.1/api";
var httpClientHandler = new HttpClientHandler();

httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
{
    return true;
};
//HttpClient = new HttpClient(httpClientHandler) { };

// Create a new HttpClient and wire it to our handler
var client = new HttpClient(httpClientHandler)
{
    //BaseAddress = new Uri(EndPoint),
    // Specify that requests should be for HTTP/3
    DefaultRequestVersion = HttpVersion.Version30,
    DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};


// Get our response
var response = await client.GetAsync("https://localhost:5001/");
// Read the body
var body = await response.Content.ReadAsStringAsync();


// Print the relevant headers to verify our results
Console.WriteLine($"HTTP Version: {response.Version}");
Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine($"Body: {body}");

ClientHTTP3.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
      <EnablePreviewFeatures>True</EnablePreviewFeatures>

  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Native.Quic.MsQuic.OpenSSL" Version="2.1.0" />
      <RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />

  </ItemGroup>

</Project>

The error shows up on var response. Kindly tell me what should i do.

haris
  • 1
  • 1
  • Are you running on compatible OS ? Win 10 does not support http3, only Windows 11 or Windows server 2022. – Anand Sowmithiran Aug 24 '22 at 10:48
  • So is there any way to run it in Windows 10? I have windows 10 OS and really need to run it. – haris Aug 24 '22 at 11:13
  • can anyone please help? – haris Aug 25 '22 at 12:08
  • Unfortunately, it won't work in Win 10 as far as I checked. refer https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/http3?view=aspnetcore-6.0. Kestrel will fall back to HTTP 2 or 1.1, and not use v3 on win10 – Anand Sowmithiran Aug 25 '22 at 12:15

0 Answers0