Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ServicePointManager安全协议冲突_C#_.net_Restsharp_System.net.mail - Fatal编程技术网

C# ServicePointManager安全协议冲突

C# ServicePointManager安全协议冲突,c#,.net,restsharp,system.net.mail,C#,.net,Restsharp,System.net.mail,在我的应用程序中,我使用RestSharp查询REST API和System.Net.Mail发送电子邮件。在程序启动时,我设置ServicePointManager.SecurityProtocol属性 如果我将属性设置为: ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; ServicePoin

在我的应用程序中,我使用RestSharp查询REST API和System.Net.Mail发送电子邮件。在程序启动时,我设置ServicePointManager.SecurityProtocol属性

如果我将属性设置为:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11;
使用RestSharp查询API时引发异常:

The request was aborted: Could not create SSL/TLS secure channel
如果我将属性设置为:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
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

如何解决此问题?

REST API服务器和您连接的邮件服务器显然有冲突的安全协议要求。您需要为它们使用不同的安全协议设置

是静态的,其当前值适用于所有新连接。不幸的是,没有办法控制此设置。(我认为这是微软的设计缺陷)

如果您可以控制RESTAPI服务器或邮件服务器,那么您可能可以重新配置它们以接受无冲突的安全协议

否则,您可以重新设计代码,以便所有到REST API和邮件服务器的连接都由两个独立的服务器建立

例如,让默认应用程序域处理所有REST API通信,并生成一个单独的应用程序域来处理所有邮件通信


使用此设置,您可以在每个域中使用不同的值。(因为应用程序域之间不共享静态值)。

什么版本的.NET?如果您不是最新版本,是否可以升级?在那之后,我会从缩小范围开始。使用chrome addin Postman尝试与您的API通信。设置Fiddler(或wireshark)拦截流量,并查看数据包以查看它试图协商的内容。您是否只使用标准的SmtpClient类?您的代码在使用时是什么样子的?您可以在拨打电话之前为service point manager设置正确的值。