.net 报错 远程主机强迫关闭了一个现有的连接 问题分析解决

先测试cmd 发现可以ping通地址:证明不是网络问题

postman 报错

Error: Hostname/IP does not match certificate's altnames

设置里ssl验证默认开启,把选项关闭,接着就正常了:证明应该是https或ssl 相关通讯出现问题

visual studio 报错

远程主机强迫关闭了一个现有的连接

原先项目框架是.net 4.0 没有问题 升级成.net4.5.2后开始报错

原因分析

https前缀会有ssl证书验证,在post调取该地址时,可以忽略掉该验证,否则会产生调不到的情况。

原来.net4.0的时候 调用代码前加忽略掉ssl验证

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

升级.net4.5.2之后 SecurityProtocolType的默认支持有问题

添加代码

System.Net.ServicePointManager.SecurityProtocol |= (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);

或者
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

相关推荐
周杰伦fans1 天前
C# required 关键字详解
开发语言·网络·c#
游乐码1 天前
c#ArrayList
开发语言·c#
唐青枫1 天前
C#.NET Monitor 与 Mutex 深入解析:进程内同步、跨进程互斥与使用边界
c#·.net
周杰伦fans1 天前
cad文件选项卡不见了怎么办?
c#
llm大模型算法工程师weng1 天前
Python敏感词检测方案详解
开发语言·python·c#
会写代码的建筑师1 天前
.NET 控制台后台程序实践细节总结
后端·.net
游乐码1 天前
c#stack
开发语言·c#
橘子编程1 天前
编程语言全指南:从C到Rust
java·c语言·开发语言·c++·python·rust·c#
阿捞21 天前
在 .NET 中使用 Moonshot Kimi + AgentFramework:从 SDK 到 Agent 的完整实践
html·.net·xhtml
zztfj1 天前
C# 异步方法 async / await CancellationToken 设置任务超时并手动取消耗时处理
c#·异步