.NET 4.8 RestClient带证书、基础认证和代理调用报0X8009030D错误求助
C# .NET 4.8调用证书+基础认证Web服务时SSL/TLS通道创建失败问题
我正在使用C# .NET 4.8应用调用一个通过证书和基础认证保护的Web服务,调用时出现错误:
System.Net Error: 0 : [3564] AcquireCredentialsHandle() failed with error 0X8009030D.
进而抛出:
The request was aborted: Could not create SSL/TLS secure channel.
我查阅了多篇帖子但未取得进展,相关代码如下:
ServicePointManager.SecurityProtocol = spt; ServicePointManager.Expect100Continue = true; ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; RestClient client = new RestClient(uri); client.Authenticator = new HttpBasicAuthenticator(username, password); client.ClientCertificates = new X509CertificateCollection(); client.ClientCertificates.Add(new X509Certificate(certificate, certificatePassword)); client.Proxy = new WebProxy(proxy, port); client.Proxy.Credentials = CredentialCache.DefaultCredentials; request = new RestRequest(Method.POST); request.AddHeader("Message-Key", messageKey); request.RequestFormat = DataFormat.Json; request.AddParameter("application/json", json, ParameterType.RequestBody); IRestResponse response = client.Execute(request);
证书为pfx文件,使用SoapUI执行相同调用可成功。我已配置生成System.Net跟踪日志,日志中首先出现:
System.Net Error: 0 : [3564] Can't retrieve proxy settings for Uri 'https://dev.api.sydney.edu.au/usyd-message-handler-exp-api-v1/v1/messages'. Error code: 12180.
我认为此问题不大,因为未配置代理时调用会超时。日志末尾显示:
[Thumbprint] 0C1EFA37718255EE6DEF3A8A980CD30939762EA6 . System.Net Information: 0 : [3564] SecureChannel#14353717 - Found the certificate in the LocalMachine store. System.Net Information: 0 : [3564] SecureChannel#14353717::.AcquireClientCredentials, new SecureCredential() (flags=(ValidateManual, NoDefaultCred, SendAuxRecord, UseStrongCrypto), m_ProtocolFlags=(Ssl3Client, Tls12Client), m_EncryptionPolicy=RequireEncryption) System.Net Information: 0 : [3564] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc = System.Net.SecureCredential) System.Net Error: 0 : [3564] AcquireCredentialsHandle() failed with error 0X8009030D. System.Net Information: 0 : [3564] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc = System.Net.SecureCredential) System.Net Error: 0 : [3564] AcquireCredentialsHandle() failed with error 0X8009030D. System.Net.Sockets Verbose: 0 : [3564] Entering Socket#32115247::Dispose() System.Net Error: 0 : [3564] Exception in HttpWebRequest#24230272:: - The request was aborted: Could not create SSL/TLS secure channel.. System.Net Error: 0 : [3564] Exception in HttpWebRequest#24230272::EndGetRequestStream - The request was aborted: Could not create SSL/TLS secure channel.. System.Net Information: 0 : [10700] ServicePoint#16495015 - Closed as idle.
我尝试了ServicePointManager.SecurityProtocol的所有可能组合,若不设置或至少包含Tls12则出现此问题,否则会出现底层连接关闭错误。恳请提供解决思路。
内容的提问来源于stack exchange,提问作者Tony C
相关产品推荐
相关产品推荐

