title: Httpclient with SSL is working from Visual studio 2015\or from my Laptop but not working from windows server 2012
body: <p>I have simple application which is basically POST ( Postasnyc) message to RESTApi using HttpClient. .Net framework is .Net 4.5.2. This code is working fine from mylatop (WIndows 7), but it is not from Windows server 2012. I tried different windows server, no where it worked other than my laptop. But from the same server SOAPUI is working ( used the .pfx for SSL , created it from actual cert ). This is an issue with no clue.</p>
  
  <p>Note: I have made sure the certs are installed on server.</p>
  
  <p>I tried the following
  1. Made sure no fire wall in between
  2. Set Timeout for http client
  3. ServicePointManager.CertificatePolicy = new MyPolicy(); - didn't help
  4. await client.PostAsync(objSearch.Resource, content).ConfigureAwait(false); - didnt help</p>
  
  <p>Note: I have gone through so many forums, and tried almost all suggestions.</p>
  
  <p>Code snippet is given below</p>
  
  <pre><code>WebRequestHandler handler = new WebRequestHandler();
  
  X509Certificate2 certificate = GetCertificateFromStore(); // getting the correct certs in server as well.
  
  handler.ClientCertificates.Add(certificate);
  
  handler.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
  
          try
          {
  
              using (var client = new HttpClient(handler))
              {
                  System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls |  SecurityProtocolType.Tls11; 
                  client.BaseAddress = new Uri(objSearch.url);
                  //client.MaxResponseContentBufferSize = 2147483647;
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
  
                  // HTTP GET
                  //MessageBox.Show("Ready To post");
                  // client.Timeout = TimeSpan.FromSeconds(10); - didnt work
                  var response = await client.PostAsync(objSearch.Resource, content);
  </code></pre>
  
  <blockquote>
    <p>Error Message. System.Net.Http.HttpRequestException: An error occurred
    while sending the request. ---> System.Net.WebException: The
    underlying connection was closed: An unexpected error occurred on a
    send. ---> System.IO.IOException: Unable to read data from the
    transport connection: A connection attempt failed because the
    connected party did not properly respond after a period of time, or
    established connection failed because connected host has failed to
    respond. ---> </p>
    
    <p>System.Net.Sockets.SocketException: A connection attempt failed
    because the connected party did not properly respond after a period of
    time, or established connection failed because connected host has
    failed to respond</p>
    
    <p>at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)</p>
    
    <p>at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult
    asyncResult)</p>
    
    <p>--- End of inner exception stack trace ---    at
    System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)</p>
    
    <p>at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)</p>
    
    <p>at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)</p>
    
    <p>--- End of inner exception stack trace ---    at
    System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
    asyncResult, TransportContext&amp; context)    at
    System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult
    ar)    --- End of inner exception stack trace ---</p>
    
    <p>at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)</p>
    
    <p>at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</p>
    
    <p>at RIBS.AccountService.PDFIntegrator.d__1.MoveNext() </p>
    
    <p>at RIBS.AccountService.PDFIntegrator.d__1.MoveNext() </p>
    
    <p>C:\Users\311827364\Source\Repos\RIBS_Net\Solution\RIBS.AccountService\PDFIntegrator.cs:line
    142    --- End of inner exception stack trace ---    at
    System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
    includeTaskCanceledExceptions)</p>
    
    <p>at System.Threading.Tasks.Task`1.GetResultCore(Boolean
    waitCompletionNotification)</p>
    
    <p>at System.Threading.Tasks.Task`1.get_Result()</p>
    
    <p>at RIBS.AccountService.PDFStatementImpl.GetStatementList(String
    strAccountNumber, String Transit, String accType, String strResource,
    String stStartDate, String stEndDate) in </p>
    
    <p>C:\Users\311827364\Source\Repos\RIBS_Net\Solution\RIBS.AccountService\PDFStatementImpl.cs:line
    23
    ---> (Inner Exception #0) System.InvalidOperationException: Failed to get statement list from Ondemand</p>
    
    <p>at RIBS.AccountService.PDFIntegrator.d__1.MoveNext() in
    C:\Users\311827364\Source\Repos\RIBS_Net\Solution\RIBS.AccountService\PDFIntegrator.cs:line
    142&lt;---</p>
  </blockquote>