【发布时间】:2020-09-29 18:31:32
【问题描述】:
我知道有很多人在问这个问题,但我想我已经阅读了太久没有结果的答案和问题。
我有一个调用 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";
WebResponse response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
JsonSerializer serializer = new JsonSerializer();
result = (LicenseInfoDTO)serializer.Deserialize(reader, typeof(LicenseInfoDTO));
}
}
catch (Exception ex)
{
logger.Error($"Error calling SEQUAR to get info for license {license}", ex);
}
return result;
}
我已经尝试过使用此处(以及网络上的许多答案)找到的“Microsoft EasyFix”,但没有任何结果。 https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi
我还对我找到的系统注册表进行了几乎所有更改组合。
我要检查密码,但我不是很专业,不知道在哪里寻找而不随机搜索奇怪的东西。
有人对此有神奇的解决方案吗?快把我们逼疯了。
谢谢!
编辑:使用 http 而不是 https 它可以工作。
【问题讨论】:
标签: c# ssl windows-7 .net-4.5 tls1.2