M
maimalash
Guest
i got this Error System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
And this is my code
Public Function CreateWebRequest(url As String, action As String) As HttpWebRequest
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateServerCertificate
' Dim FilePath = Server.MapPath("/lastKSS.cer")
' Dim cert As New X509Certificate2(FilePath, "P@ssword", X509KeyStorageFlags.Exportable)
Dim webRequest As HttpWebRequest = CType(webRequest.Create(url), HttpWebRequest)
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
webRequest.Credentials = CredentialCache.DefaultCredentials
Try
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
Dim signingCert = store.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, False)
If signingCert.Count > 0 Then
SharedFunctions.Log("GetPublicKey" & signingCert(0).GetPublicKey.ToString)
webRequest.ClientCertificates.Add(signingCert(0))
End If
Catch ex As Exception
End Try
' webRequest.ClientCertificates.Add(cert)
' webRequest.ProtocolVersion = HttpVersion.Version10
' webRequest.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired
webRequest.Headers.Add("SOAPAction", action)
webRequest.ContentType = "text/xml;charset=""utf-8"""
webRequest.Accept = "text/xml"
webRequest.Method = "POST"
webRequest.AllowAutoRedirect = True
webRequest.Credentials = CredentialCache.DefaultCredentials
webRequest.AllowWriteStreamBuffering = True
Return webRequest
End Function
Continue reading...
And this is my code
Public Function CreateWebRequest(url As String, action As String) As HttpWebRequest
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateServerCertificate
' Dim FilePath = Server.MapPath("/lastKSS.cer")
' Dim cert As New X509Certificate2(FilePath, "P@ssword", X509KeyStorageFlags.Exportable)
Dim webRequest As HttpWebRequest = CType(webRequest.Create(url), HttpWebRequest)
Dim store As New X509Store(StoreName.My, StoreLocation.LocalMachine)
webRequest.Credentials = CredentialCache.DefaultCredentials
Try
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
Dim signingCert = store.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, False)
If signingCert.Count > 0 Then
SharedFunctions.Log("GetPublicKey" & signingCert(0).GetPublicKey.ToString)
webRequest.ClientCertificates.Add(signingCert(0))
End If
Catch ex As Exception
End Try
' webRequest.ClientCertificates.Add(cert)
' webRequest.ProtocolVersion = HttpVersion.Version10
' webRequest.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequired
webRequest.Headers.Add("SOAPAction", action)
webRequest.ContentType = "text/xml;charset=""utf-8"""
webRequest.Accept = "text/xml"
webRequest.Method = "POST"
webRequest.AllowAutoRedirect = True
webRequest.Credentials = CredentialCache.DefaultCredentials
webRequest.AllowWriteStreamBuffering = True
Return webRequest
End Function
Continue reading...