title: Unable to send HTTPS request
body: <p>I have to send an HTTPS POST request.
  I created a library class to send the HTTPS POST request.
  I have 2 programs calling this library class:</p>
  
  <ul>
  <li>My main program (IdentityServer)</li>
  <li>My test class</li>
  </ul>
  
  <p>Both programs only call the library class with the given arguments (to be used on POST body) and the library class performs the request.</p>
  
  <p>The problem is that, when running this on my test class it works fine. However with IdentityServer it throws the following error "System.Net.Http.WinHttpException".</p>
  
  <p>The only difference I note between the test class and IdentityServer is their 'target framework':</p>
  
  <ul>
  <li>IdentityServer (.NET Core 2.0)</li>
  <li>Test Class (.NET Framework 4.6.1)</li>
  <li>Class Library (.NET Framework 4.6.1)</li>
  </ul>
  
  <p>And this is my simple code to send the request:</p>
  
  <pre><code>public static async Task&lt;HttpStatusCode&gt; Send(String destination, String message, String accountUsername, String accountPassword, String senderPhoneNumber)
      {
  
          var values = new Dictionary&lt;string, string&gt;
          {
              { "username", accountUsername },
              { "password", accountPassword },
              { "src", senderPhoneNumber },
              { "dst", destination },
              { "text", message },
              { "srr", "3" }
          };
  
          var content = new FormUrlEncodedContent(values);
  
          HttpStatusCode responseStatus = HttpStatusCode.NotAcceptable;
  
          try
          {
              HttpClient client = new HttpClient();
  
              ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
  
              ServicePointManager
                  .ServerCertificateValidationCallback +=
                  (sender, cert, chain, sslPolicyErrors) =&gt; true;
  
              var response = await client.PostAsync("TARGET_URL", content);
              var responseString = await response.Content.ReadAsStringAsync();
              responseStatus = response.StatusCode;
          }
          catch (WebException we)
          {
              string error = we.ToString();
          }
          catch (Exception e)
          {
              string error = e.ToString();
          }
          return responseStatus;
      }
  </code></pre>
  
  <p>I ignore the certificate from the target server since their certificate is invalid.</p>
  
  <p>But, as I said, it works just fine calling this with my test class.</p>
  
  <p>The complete error thrown when calling from IdentityServer is the following:</p>
  
  <pre><code>    System.Net.Http.HttpRequestException: An error occurred while sending the request. ---&gt; System.Net.Http.WinHttpException: A security error occurred
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
     at System.Net.Http.WinHttpHandler.&lt;StartRequest&gt;d__105.MoveNext()
     --- End of inner exception stack trace ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Net.Http.HttpRequestException: An error occurred while sending the request. ---&gt; System.Net.Http.WinHttpException: A security error occurred
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
     at System.Net.Http.WinHttpHandler.&lt;StartRequest&gt;d__105.MoveNext()
     --- End of inner exception stack trace ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at System.Net.Http.DiagnosticsHandler.&lt;SendAsync&gt;d__2.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at System.Net.Http.HttpClient.&lt;FinishSendAsyncBuffered&gt;d__58.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at VdfnHungSMSLibrary.VdfnHungSMSProvider.&lt;Send&gt;d__0.MoveNext() in D:\Projects\IdentityServer\Current\src\VdfnHungSMSLibrary\VdfnHungSMSProvider.cs:line 43
  </code></pre>