c# 通过HttpRequest发起HttpPost请求时提示 基础连接已经关闭: 接收时发生意外错误

问题描述:

发送短信或其他操作时,会调用第三方接口 获取相应的返回数据结果

1)对方给的接口是 以http 开头的 你这边同样是以http方式请求的 是没有问题的

2)如果你这边请求是以https 或 http 都可以 ,那就要把对方的请求接口改成 https的

3)以HttpRequest请求时 需要添加以下代码

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.DefaultConnectionLimit = 512;
ServicePointManager.Expect100Continue = false;
Rst = WebRequest.Create(url) as HttpWebRequest;
Rst.ProtocolVersion = HttpVersion.Version10;

具体描述 可以点上去查看详情

原文地址:https://www.cnblogs.com/qingjiawen/p/14522686.html