C# 具有Net Core 3和HttpClient的HTTP/2请求

C# 具有Net Core 3和HttpClient的HTTP/2请求,c#,.net-core,dotnet-httpclient,http2,.net-core-3.1,C#,.net Core,Dotnet Httpclient,Http2,.net Core 3.1,我正试图使用以下代码在C#/NetCore中发出HTTP/2请求: public static class WebClient { public static void Main(string[] args) { AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); HttpResponseMessage response = Client.G

我正试图使用以下代码在C#/NetCore中发出HTTP/2请求:

public static class WebClient
{
    public static void Main(string[] args) 
    {
        AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
        HttpResponseMessage response = Client.GetAsync("https://http2.pro/api/v1").Result;
        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        Console.WriteLine(response.Version);
    }

    private static readonly CookieContainer CookieContainer =
        new CookieContainer();

    private static readonly HttpClientHandler HttpClientHandler =
        new HttpClientHandler
        {
            CookieContainer = CookieContainer,
            MaxConnectionsPerServer = 5,
        };

    public static readonly HttpClient Client = new HttpClient(HttpClientHandler)
    {
        Timeout = Timeout.InfiniteTimeSpan,
        DefaultRequestVersion = new Version(2, 0)
    };
}

但是,服务器总是使用HTTP 1.1进行响应。有人知道问题出在哪里吗?如果这很重要的话,我正在Windows 7上使用Net Core 3.1.101。

一定是Windows 7的东西。当我在Win10中运行http2时,它显示http2。也许有一个注册表调整,你可以做,或者可能只是不支持。必须是Windows7的东西。当我在Win10中运行http2时,它显示http2。也许有一个注册表调整,你可以做,或者可能只是不支持。