我正在尝试使用以下代码在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。