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.