title: Https leads to exception using HttpClient
body: <p>I have a problem calling my ASP.NET Web API from a client application. Many questions regarding this topic were asked here but none of the answers solved my issue.</p>
  <p><strong>Problem:</strong></p>
  <p>When I try to call my API I get the following exception:</p>
  <blockquote>
  <p>System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host</p>
  </blockquote>
  <p><strong>Info:</strong></p>
  <ul>
  <li>Both projects (cleint and API) are based on .NET 4.5.2</li>
  <li>In my test environment client and API are running on the same VM</li>
  <li>Everything worked fine wihtout https</li>
  <li>I created a selfsigned certificate for testing purposes but no browser shows a warning so it seems to be fine</li>
  </ul>
  <p><strong>Code:</strong></p>
  <pre><code>HttpClient client = new HttpClient();
  
  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  
  client.BaseAddress = new Uri(apiBaseUrl);
  client.DefaultRequestHeaders.Accept.Clear();
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
  HttpResponseMessage response = await client.PostAsJsonAsync(&quot;call/CreateNew&quot;, call);
  </code></pre>
  <p>I tried several solutions provided in the answers of similar questions, but none of these worked so far:</p>
  <ul>
  <li>Using .NET Framework 4.6 instread of 4.5.2</li>
  <li>Specified the protocol with <code>ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;</code></li>
  <li>Tried <code>ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };</code> (just to be sure)</li>
  </ul>
  <p>In another question someone suggested using Wireshark to further analyze the problem. I gave it a try but I have to admit that I did not really know what I was doing.</p>
  <p>Anyway I found segments that said &quot;<strong>ACKed segment that wasn't captured</strong>&quot; and &quot;<strong>Previous segment(s) not captured</strong>&quot; of which the second contained data I actually tried to send to my API.</p>
  <p>Can you give me some advice what to try next or how to fix this error?</p>