C# 服务HTTPS 对 请求被中止: 未能创建 SSL/TLS 安全通道报错

1.如果windows支持HTTPS的TLS协议,则可以直接跳过 (Tls12)

WebMethod(Description = "获取HttpsPost加密服务.")

public string HTTPSPOST(String input,String sUrl)

{

Log.Add("ReceiveNotice", "HTTPSPOST", "入参sUrl:" + sUrl + ",input:" + input);

HttpWebRequest webReq = null;

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);

// 此处对HTTPS校验 TLS进行跳过

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

webReq = WebRequest.Create(sUrl) as HttpWebRequest;

webReq.ProtocolVersion = HttpVersion.Version10;

webReq.Method = "POST";

webReq.ContentType = "application/json";

StreamWriter writer = new StreamWriter(webReq.GetRequestStream());

writer.Write(input);

writer.Flush();

HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();//获取服务器返回的结果

Stream getStream = response.GetResponseStream();

StreamReader streamreader = new StreamReader(getStream, Encoding.UTF8);

String result = streamreader.ReadToEnd();

Log.Add("ReceiveNotice", "HTTPSGET", "出参:" + result);

return result;

}

2.如果postman能测试通过,服务一直返回 请求被中止: 未能创建 SSL/TLS 安全通道

则判断Windows是否支持 TLS12

验证系统是否支持TLS1.2、TLS1.3

WIN+R PowerShell 打开:

Net.ServicePointManager::SecurityProtocol

Net.ServicePointManager::SecurityProtocol = Net.SecurityProtocolType::Ssl3 -bor Net.SecurityProtocolType::Tls -bor Net.SecurityProtocolType::Tls11 -bor Net.SecurityProtocolType::Tls12

返回:Ssl3, Tls, Tls11, Tls12 则支持TLS12

如果返回不包含 Tls11, Tls12 先注册表注册试试看是否可以。

如果不行,则系统升级到Windows10 或者 服务器系统 升级 server 2016

相关推荐
特立独行的猫A12 小时前
别再用 nohup 了:让应用在后台常驻的正确姿势与 systemd 服务详解
java·后端·python
一起_java12 小时前
技术文章-基于Dify-Agent的智能问答系统设计与实现
java·spring boot·后端·agent·dify
Flynn Liang13 小时前
I/O 密集型高并发实战:Java 服务 10 维优化,从线程打满到 10 万 QPS
java·spring boot·性能优化·高并发·系统设计·虚拟线程·io密集型
吃我一窝jio14 小时前
Python与Go线程模型深度对比
java·开发语言·python
这个昵称不容易15 小时前
SpringBoot 购物推荐网站的设计与实现:120 个 Java 文件、147 个接口、13 张表,附真实运行截图
java·springboot·毕设
文丑颜不良啊15 小时前
LeetCode3041~3060题目解析
java·leetcode
文丑颜不良啊16 小时前
LeetCode3101~3120题目解析
java·leetcode
Resean022316 小时前
SpringMVC 6+源码分析(十一)视图渲染与异步请求(收尾篇)
java·spring·springmvc
何以解忧唯有撸码17 小时前
开源】当桌面图标开始打台球:我用 WinForms 做了一桌“真的”台球
c#·winform·自定义控件·gdi
靠沿17 小时前
MySQL数据库进阶——存储过程和触发器
java·数据库·mysql