【发布时间】:2015-11-10 22:19:31
【问题描述】:
在我的应用程序中,我使用 RestSharp 查询 REST API 并使用 System.Net.Mail 发送电子邮件。在程序启动时,我设置了 ServicePointManager.SecurityProtocol 属性。
如果我将属性设置为:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
使用 RestSharp 查询 API 时抛出异常:
The request was aborted: Could not create SSL/TLS secure channel
如果我将属性设置为:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11;
使用 System.Net.Mail 发送电子邮件时引发异常:
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm
我应该如何解决这个问题?
【问题讨论】:
-
什么版本的 .NET?如果你不是最新的,是否可以升级?在那之后,我会开始尝试缩小范围。使用 chrome 插件 Postman 尝试与您的 API 进行通信。设置 Fiddler(或 wireshark)来拦截流量并查看数据包以查看它试图协商的内容。您还只是使用标准的 SmtpClient 类吗?使用它的代码是什么样的?
-
您可以在拨打电话之前为服务点管理器设置正确的值。
标签: c# .net restsharp system.net.mail