Vio*_*rel 0 c# httpwebrequest ssl-certificate windows-7 winforms
我遇到以下问题:
如果我使用网络浏览器打开地址https://info.protectiacivila.ro/test.php
,则显示文本“Hello!” 被展示。
我在 Windows 窗体应用程序中编写了以下单击事件处理程序(目标:.NET 4.5):
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);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的方法应该显示消息“Hello!”
它在Windows 10中完美运行。这意味着SSL证书是有效的。
但是,在 Windows 7 中,它会显示错误消息:
请求已中止:无法创建 SSL/TLS 安全通道。
我该怎么做才能使上述方法在 Windows 7 中也起作用?
谢谢
小智 7
Windows 7 SP1 似乎支持 TLS 1.1 和 1.2,但默认情况下未启用它\xc2\xb4s。例如,当您想在 Windows 7 上使用 GIT 时,也会出现此错误。解决方案是通过注册表启用它:
\nHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\TLS 1.2\\Client\nRun Code Online (Sandbox Code Playgroud)\nDisabledByDefault来源:https://manage.accuwebhosting.com/knowledgebase/3008/How-do-I-enable-TLS-1-2-on-Windows-7.html
\n| 归档时间: |
|
| 查看次数: |
3393 次 |
| 最近记录: |