花Q花Q 2022-03-12 13:38 采纳率: 0%
浏览 148

请求被中止: 未能创建 SSL/TLS 安全通道


   public static string PostData(string postUrl, string paramData, Encoding dataEncode)
        {
            string ret = string.Empty;
            try
            {
                Console.WriteLine(postUrl + paramData);
                string result = string.Empty;
                byte[] byteArray = dataEncode.GetBytes(paramData);
                HttpWebRequest webReq = null;
                if (postUrl.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine("https");
                    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)0x300 | (SecurityProtocolType)0xC00;
                    ServicePointManager.ServerCertificateValidationCallback += CheckValidationResult;
                    //ServicePointManager.CheckCertificateRevocationList = false;
                    //ServicePointManager.DefaultConnectionLimit = 512;
                    //ServicePointManager.Expect100Continue = false;
                    webReq = WebRequest.Create(postUrl) as HttpWebRequest;
                    //webReq.ProtocolVersion = HttpVersion.Version10;
                }
                else
                {
                    webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                }
                webReq.Method = "post";
                webReq.ContentType = "application/json";
                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();

                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                }
                Console.WriteLine(result);
                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return ret;
        }



        public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true;
        }

访问https接口

一台服务器有返回结果 这台服务器.netframework 4.7

另一台服务器返回结果为请求被中止: 未能创建 SSL/TLS 安全通道 这台服务器.netframework 4.0

有知道吗

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 创建了问题 3月12日

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料