I know that there are many references to this error but I am struggling to resolve the issue despite looking at and trying many of the suggested solutions.
The error only happens on certain machines. It does not happen on my dev machine nor on many others but we are able to repeat this on a Windows 2008 RS server as well as Windows 2012R2 as well as possibly others.
I am able to reach the page in a browser on the affected machine so this would exclude a lack of ciphers (or so I was told).
Each time I run my simple code I get the same error on some machines:
The request was aborted: Could not create SSL/TLS secure channel.
My simple code is this:
Private Async Function CallRest() As Task
Using http As HttpClient = New HttpClient()
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim url As String = "https://www.zeidman.info/appreg/resttest.php"
Dim result = Await http.GetAsync(url)
Dim content = Await result.Content.ReadAsStringAsync
Console.WriteLine(content)
End Using
End Function
I have tried adding:
ServicePointManager.Expect100Continue = True
For testing purposes I have tried adding:
ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications
with the corresponding function
Public Function AcceptAllCertifications(sender As Object,
certification As System.Security.Cryptography.X509Certificates.X509Certificate,
chain As System.Security.Cryptography.X509Certificates.X509Chain,
sslPolicyErrors As Security.SslPolicyErrors) As Boolean
Return True
End Function
I also saw this answer and used that version of the ServerCertificateValidationCallback but the code does not even go into that method (I put logging inside it)
One comment in this question suggested a system.net trace and despite following the instructions I have not been able to get that to show any output.
Any suggestions would be very welcome.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12on top of everything (before you create a HttpClient instance). 2) .Net 4.5+ must be installed in the target machine. 3) That site uses TLS12 only, the cipher suite isTLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, which is one of the default TLS12 ciphers, it can be used to encrypt a symmetric key in the SSL handshake (not a signing-only cipher). 4) HSTS is disabled, so setting auser-agentheader is not strictly required, but it should be done anyway, for generic compatibility.Shared) HttpClient, setting defaults manually using a specific HttpClientHandler. It's the HttpClientHandler that should manage theServerCertificateCustomValidationCallback, handleAllowAutoRedirectand theCookieContainer. Always add a CookieContainer when connecting to web sites. The User-Agent can be specifies with[HttpClient].DefaultRequestHeaders.Add("User-Agent", "A not so recent User-Agent header"). Not so recent because HSTS is not supported yet.