我知道有很多人问这个问题,但我想我已经阅读了答案和问题很长时间了,但没有任何结果。
我有一个调用 Web 服务的 C# 应用程序。在 Windows 10 上一切正常,但当我在 Windows 7(或 Windows Server 2008 R2 或 Windows Server 2012)上运行该应用程序时,会抛出异常“无法创建 ssl/tls 安全通道”。
我将 TLS1.2 与 .NET Framework 4.5 结合使用(说实话,真正的应用程序是 4.0,我正在使用解决方法来启用 TLS1.2,但我已经使用 4.5 和本机 TLS1 创建了一个测试应用程序。 2管理,仍然有同样的问题:所以它与解决方法无关)。
即使在 Windows7 上,使用 Postman 进行相同的调用也能正常工作。
这是我的代码
public static LicenseInfoDTO GetLicenseInfo()
{
LicenseInfoDTO result = null;
Uri uri =_myUri;
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.Expect100Continue = true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Accept = "application/json";
request.Headers.Add("AuthToken", SECURITY_TOKEN);
request.Method = "GET"; …Run Code Online (Sandbox Code Playgroud)