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

相关推荐
草履虫建模15 小时前
力扣算法 1768. 交替合并字符串
java·开发语言·算法·leetcode·职场和发展·idea·基础
.房东的猫17 小时前
ERP(金蝶云星空)开发【安装篇】
c#
qq_2975746717 小时前
【实战教程】SpringBoot 实现多文件批量下载并打包为 ZIP 压缩包
java·spring boot·后端
老毛肚17 小时前
MyBatis插件原理及Spring集成
java·spring·mybatis
学嵌入式的小杨同学17 小时前
【Linux 封神之路】信号编程全解析:从信号基础到 MP3 播放器实战(含核心 API 与避坑指南)
java·linux·c语言·开发语言·vscode·vim·ux
lang2015092817 小时前
JSR-340 :高性能Web开发新标准
java·前端·servlet
Re.不晚18 小时前
Java入门17——异常
java·开发语言
缘空如是18 小时前
基础工具包之JSON 工厂类
java·json·json切换
追逐梦想的张小年18 小时前
JUC编程04
java·idea
好家伙VCC18 小时前
### WebRTC技术:实时通信的革新与实现####webRTC(Web Real-TimeComm
java·前端·python·webrtc