title: C# HttpClient Request HTTPS Exception error
body: <p>I am getting an intermittent error with a MVC Web App on the .NET Core 2.2 that sends Http requests to get information from various APIs.</p>
  
  <p>I believe the error is related to the URI being a https instead of a http as other calls to other APIs without the https work absolutely fine. Even with the Client Handler defining the certificate and protocol settings I still get this exception error every now and again:</p>
  
  <blockquote>
    <p>An error occurred while sending the request.</p>
    
    <p>at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, 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.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task<code>1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
     at tf.PriceService.Core.Classes.WilliamHillMatching.GetHorsesFromEvent(String eventid) in C:\agent\_work\9\s\src\tf.PriceService.Core\Classes\WilliamHillMatching.cs:line 316
     at tf.PriceService.Core.Classes.WilliamHillMatching.getPrices(List</code>1 whCompetitions, Race tfRaceData) in C:\agent_work\9\s\src\tf.PriceService.Core\Classes\WilliamHillMatching.cs:line 94
     at tf.PriceService.Core.Services.PriceService.&lt;>c__DisplayClass50_0.&lt;b__3>d.MoveNext() in C:\agent_work\9\s\src\tf.PriceService.Core\Services\PriceService.cs:line 173
     --- End of stack trace from previous location where exception was thrown ---
     at tf.PriceService.Core.Services.PriceService.getBookmakerRacePrices(DateTime workDate, List`1 tfPriceList, Race tfRaceData) in C:\agent_work\9\s\src\tf.PriceService.Core\Services\PriceService.cs:line 178
     at tf.PriceService.Core.Services.PriceService.processRacePrices(Object state) in C:\agent_work\9\s\src\tf.PriceService.Core\Services\PriceService.cs:line 341</p>
  </blockquote>
  
  <p>Here is the code:</p>
  
  <pre><code>    public static async Task&lt;WilliamHillData.Market&gt; GetHorsesFromEvent(string eventid)
      {
          string res = "";
  
          using (HttpClientHandler handler = new HttpClientHandler())
          {
              handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) =&gt; true;
              handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
  
              using (HttpClient client = new HttpClient(handler))
              {
                  client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                  client.DefaultRequestHeaders.TryAddWithoutValidation("apiKey", "key");
  
                  using (HttpResponseMessage response = await client.GetAsync("https://gw.whapi.com/v2/sportsdata/events/" + eventid + "/?&amp;includeAllDescendants=true"))
                  {
                      res = await response.Content.ReadAsStringAsync();
                  }
              }
          }
  
          JObject jobject = JObject.Parse(res);
          List&lt;WilliamHillData.Market&gt; list = jobject["markets"].ToObject&lt;List&lt;WilliamHillData.Market&gt;&gt;().ToList();
          list[0].eventid = eventid;
  
          return list[0];
      }
  </code></pre>
  
  <p>It seems to point out this specific part:</p>
  
  <pre><code> using (HttpResponseMessage response = await client.GetAsync("https://gw.whapi.com/v2/sportsdata/events/" + eventid + "/?&amp;includeAllDescendants=true"))
                  {
                      res = await response.Content.ReadAsStringAsync();
                  }
  </code></pre>
  
  <p>Am I missing something from my Http request? Is there an alternative way?</p>