title: HTTPS request fails using HttpClient
body: <p>I am using the following code and get <code>HttpRequestException</code> exception:</p>
  
  <pre><code>using (var handler = new HttpClientHandler())
  {
      handler.ClientCertificateOptions = ClientCertificateOption.Manual;
      handler.SslProtocols = SslProtocols.Tls12;
      handler.ClientCertificates.Add(new X509Certificate2(@"C:\certificates\cert.pfx"));
  
      // I also tried to add another certificates that was provided to https access 
      // by administrators of the site, but it still doesn't work.
      //handler.ClientCertificates.Add(new X509Certificate2(@"C:\certificates\cert.crt"));
      //handler.ClientCertificates.Add(new X509Certificate2(@"C:\certificates\cert_ca.crt"));
  
      using (var client = new HttpClient(handler))
      {
          var response = client.GetAsync("https://someurl.com/api.php?arg1=some&amp;arg2=test").GetAwaiter().GetResult();
          // ^ HttpRequestException: An error occurred while sending the request.
      }
  }
  </code></pre>
  
  <p>The exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>WinHttpException: A security error occurred
      System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult()
      System.Net.Http.WinHttpHandler+&lt;StartRequest&gt;d__105.MoveNext()
  
  HttpRequestException: An error occurred while sending the request.
      System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult()
      System.Net.Http.HttpClient+&lt;FinishSendAsync&gt;d__58.MoveNext()
      System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      System.Runtime.CompilerServices.TaskAwaiter.GetResult()
      MyApp.Web.Controllers.HomeController.Test() in HomeController.cs
          var response = client.GetAsync("https://someurl.com/api.php?arg1=some&amp;arg2=test").GetAwaiter().GetResult();
      lambda_method(Closure , object , Object[] )
      Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+&lt;InvokeActionMethodAsync&gt;d__27.MoveNext()
  </code></pre>
  
  <p>I also tried to export the same certificates to Windows Certificate Store and use it via Google Chrome and it works fine (browser asked me to confirm installed certificate and then loaded the resource).</p>
  
  <p>Why it's not working in my code?</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>I also tried to add callback to validate the certificate:</p>
  
  <pre><code>handler.ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) =&gt;
  {
      // I set a breakpoint to this point but it is not catched.
      return true;
  };
  </code></pre>
  
  <p><strong>UPDATED2</strong></p>
  
  <p>The certificate is used SHA-1. Neil Moss is mentioned in the comments that <a href="https://blogs.windows.com/msedgedev/2016/04/29/sha1-deprecation-roadmap/" rel="noreferrer">support for SHA1 certs is being withdrawn</a>.
  If it is the real reason why it is not working, is there workaround for it?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Thank you Neil Moss for solution. He proposed to use Tls flag for SSL protocol. </p>
  
  <pre><code>handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
  </code></pre>
  
  <p>But it also required the following:</p>
  
  <pre><code>handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =&gt; true;
  </code></pre>
  
  <p>After I added this one it works fine.</p>