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

相关推荐
胚芽鞘68144 分钟前
关于java项目中maven的理解
java·数据库·maven
岁忧2 小时前
(LeetCode 面试经典 150 题 ) 11. 盛最多水的容器 (贪心+双指针)
java·c++·算法·leetcode·面试·go
CJi0NG2 小时前
【自用】JavaSE--算法、正则表达式、异常
java
Hellyc2 小时前
用户查询优惠券之缓存击穿
java·redis·缓存
今天又在摸鱼3 小时前
Maven
java·maven
老马啸西风3 小时前
maven 发布到中央仓库常用脚本-02
java·maven
代码的余温3 小时前
MyBatis集成Logback日志全攻略
java·tomcat·mybatis·logback
我是苏苏4 小时前
C#基础:Winform桌面开发中窗体之间的数据传递
开发语言·c#
一只叫煤球的猫4 小时前
【🤣离谱整活】我写了一篇程序员掉进 Java 异世界的短篇小说
java·后端·程序员
2501_915918414 小时前
Fiddler中文版全面评测:功能亮点、使用场景与中文网资源整合指南
android·ios·小程序·https·uni-app·iphone·webview