UPD: This code work in windows server 2012, but dont work in windows 7,8,10. And i haven't any idea why
I am trying to make post request to some service that allows only https connection. But i get error
The request was aborted: Could not create SSL/TLS secure channel
My code
using (var client = new HttpClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var response = await client.PostAsync(ApiAddress, content);
var xml = await response.Content.ReadAsStringAsync();
var transaction = DeserializeXml<StationsResponseTransaction>(xml);
return transaction;
}
This service gave certificate (.crt) and private key (.pem) files. Maybe i need to use these files? But how?
UPDATE: I tried create pfx certificate and add it in WebRequestHandler
WebRequestHandler handler = new WebRequestHandler();
X509Certificate2 certificate = new X509Certificate2("Certificate.pfx", "password");
handler.ClientCertificates.Add(certificate);
and use handler in client new HttpClient(handler)
But i got same error
UPDATE: Just tested this request in postman - working fine, when server's certificate accepted from google crhome. But how to accept certificate from C# httpclient?
ServicePointManager
's ServerCertificateValidationCallback
event not called