Windows 7中的错误:请求被中止:无法创建SSL / TLS安全通道

问题描述

我有以下问题:
如果我使用网络浏览器打开地址https://info.protectiacivila.ro/test.php 然后输入文字“ Hello!”显示出来。

我在Windows窗体应用程序(目标:.NET 4.5)中编写了以下click事件处理程序:

 private void button1_Click(object sender,EventArgs e) {
  Uri uri = new Uri("https://info.protectiacivila.ro/test.php");
  ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
  HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
  try {
    string strResponse;
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
      StreamReader reader = new StreamReader(response.GetResponseStream());
      strResponse = reader.ReadToEnd();
    }
    MessageBox.Show(strResponse);
  } catch (Exception ex) {
    MessageBox.Show(ex.Message);
  }
}

以上方法应显示消息“ Hello!”
它在Windows 10中完美运行。 这表示SSL证书有效。

但是,在Windows 7中会显示错误消息:
该请求已中止:无法创建SSL / TLS安全通道。

如何使上述方法在Windows 7中也能正常工作?

谢谢

解决方法

似乎 Windows 7 SP1 支持 TLS 1.1 和 1.2,但默认情况下未启用。此错误也会出现,例如当您想在 Windows 7 上使用 GIT 时。解决方案是通过注册表启用它:

  1. 您需要创建一个注册表项:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client
  1. 添加值为 DisabledByDefault 的 DWORD 32 位

来源:https://manage.accuwebhosting.com/knowledgebase/3008/How-do-I-enable-TLS-1-2-on-Windows-7.html

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...