当我向某个URL发出第三方请求时,IIS会给我错误:
请求已中止:无法创建SSL / TLS安全通道。
但是我能够从控制台应用程序和Postman向同一URL发出请求。
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
注意* URL中的方法不是文件。方法名称与方法名称一样具有.dll。 我正在使用.net Framework 4.5
答案 0 :(得分:0)
您有权访问服务器管理吗? 您能否先尝试在不提供客户端证书的情况下进行连接? 从代码中删除相应的部分,并在IIS管理控制台中关闭客户端证书要求。
如果错误仍然存在,请找出适合客户端支持的密码和适合服务器的密码。如果它们不多,则会发生与您相似的错误。 要检查客户端,请重写代码以连接到以下站点: “ https://howsmyssl.com/a/check” 如果您要连接的服务器是公共的(可见互联网),则可以使用以下站点来检查其支持的密码套件: https://www.ssllabs.com/ssltest/