简体   繁体   中英

IIS Blocking My Request. Could not create SSL/TLS secure channel

When i make third party request to some URL then IIS gives me error:

The request was aborted: Could not create SSL/TLS secure channel.

however i am able to make request to same URL from console application and Postman.

Dim certificates As X509Certificate2 = New X509Certificate2()
Dim uriPath As String = "D:\CertificateFolder\MyCert.cer"
Dim localPath As String = New Uri(uriPath).LocalPath
certificates.Import(localPath)

Dim sResult As String = ""

Dim activeProtocol As SecurityProtocolType = 
ServicePointManager.SecurityProtocol
Try
   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or 
SecurityProtocolType.Tls11
Dim oRequest As HttpWebRequest = 
WebRequest.Create("https://test.com/router.dll")
oRequest.KeepAlive = False
oRequest.Method = "POST"
oRequest.ContentType = "text/xml"
Dim Test As String = "some xml"
Dim bytes As Byte() = Text.Encoding.UTF8.GetBytes(Test)
oRequest.ContentLength = bytes.Length
oRequest.ClientCertificates = New X509CertificateCollection({certificates})
Dim oWriter As StreamWriter
Try
    Dim streamToSend As Stream = oRequest.GetRequestStream()
    oWriter = New StreamWriter(oRequest.GetRequestStream())
    streamToSend.Write(bytes, 0, bytes.Length)
    streamToSend.Close()
Catch up As Exception
    Return
Finally

End Try
Dim oResponse As HttpWebResponse = oRequest.GetResponse()
Dim oReader As New StreamReader(oResponse.GetResponseStream())
sResult = oReader.ReadToEnd
oReader.Close()
Catch
  ' do nothing for now
Finally
   ServicePointManager.SecurityProtocol = activeProtocol
End Try

Note* Method in URL is not file. Method name has .dll just as name of method. I am using .net framework 4.5

Do you have access to the server management? Could you first try to connect without providing the client certificate? Remove the corresponding part from your code and turn off the client certificate requirement in the IIS management console.

If the error still persist, find out which cipher suits the client supports and which the server. If they don't much an error similar to yours would occur. To check the client, rewrite your code to connect to the following site: " https://howsmyssl.com/a/check " If your server you are connection to is public (internet visible), you can use the following site to check its supported cipher suits: https://www.ssllabs.com/ssltest/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM