'Client HTTP/2 request on .Net Core 3.1 throw "HTTP/2 error code 'PROTOCOL_ERROR' (0x1)"

I've got a problem with HTTP/2 request by HttpClient to the external service by HTTPS on .Net Core 3.1 :

var httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Head, "https://www.example.com/87342.htm")
{
    Version = HttpVersion.Version20,
};
var response = await httpClient.SendAsync(request);

Last line throw exception

  System.Net.Http.HttpRequestException:  An error occurred while sending the request.
  ---> System.Net.Http.Http2ConnectionException: The HTTP/2 server sent invalid data on the connection. HTTP/2 error code 'PROTOCOL_ERROR' (0x1).
  at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync()
  --- End of inner exception stack trace ---
  at System.Net.Http.Http2Connection.SendHeadersAsync(HttpRequestMessage request, CancellationToken cancellationToken, Boolean mustFlush)
  at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
  at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
  at JustProject.NetCore.Program.Main() in C:\\Work\\Support\\JustProject.NetCore\\JustProject.NetCore\\Program.cs:line 66

In Wireshark traffic i see TLS1.2: Wireshark traffic

But when i update framework to .Net 5.0, it sended without problems and return 200 code. But i can't update my main project to .Net 5.0. When i choose HTTP 1.1 it work fine too.

It request work fine throwgh Chrome with h2 protocol.

Anybody has idea how i can fix it for .Net Core 3.1?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source