HttpClient does not create new connections in netstat

60 views Asked by At

I'm trying to recreate common scenario when creating new instances of httpClient will create leave TIME_WAIT connections.

        [HttpGet]
        public async Task<IActionResult> TestOne()
        {
            for (int i = 0; i < 10; i++)
            {
                using(var httpClient = GetHttpClient())
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, "https://jsonplaceholder.typicode.com/posts/1");

                    var response = await httpClient.SendAsync(request);

                    response.EnsureSuccessStatusCode();

                    var content = await response.Content.ReadAsStringAsync();

                    System.Diagnostics.Debug.WriteLine($"This is response - successfull");
                }
            }

            return Ok();
        }

        private HttpClient GetHttpClient()
        {
            var proxyHost = "ttrproxy.someproxy.net";
            var proxyPort = "8080";

            var proxy = new WebProxy
            {
                Address = new Uri($"http://{proxyHost}:{proxyPort}"),
                BypassProxyOnLocal = false,
                UseDefaultCredentials = true,
            };

            var httpClientHandler = new HttpClientHandler
            {
                Proxy = proxy,
                UseDefaultCredentials=true
            };


            httpClientHandler.PreAuthenticate = true;
            httpClientHandler.UseDefaultCredentials = false;

            var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);

            return client;
        }

Without proxy all is the same (when instead of GetHttpClient I use just new HttpClient()). After all I type

netstat -abn

but I cannot see any new opened connections...

0

There are 0 answers