Untitled

 avatar
unknown
csharp
2 years ago
1.3 kB
11
Indexable
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace HttpClientHttp2Example
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var handler = new SocketsHttpHandler();
            handler.SslOptions.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls13;
            handler.MaxConnectionsPerServer = 1;

            using (var httpClient = new HttpClient(handler))
            {
                httpClient.DefaultRequestVersion = new Version(2, 0);

                var response = await httpClient.GetAsync("https://google.com");

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Request completed successfully.");

                    if (handler.MaxConnectionsPerServer == 1)
                    {
                        Console.WriteLine("Connection should still be open.");
                    }
                    else
                    {
                        Console.WriteLine("Unable to verify if the connection is still open.");
                    }
                }
                else
                {
                    Console.WriteLine("Request failed.");
                }
            }
        }
    }
}
Editor is loading...