当前位置: 首页 > news >正文

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

编写代码,使用HttpWebRequest访问网页,错误提示:

未能创建 SSL/TLS 安全通道

页面本来是Http网址,突然转换为https网址,所以遇到这个问题也算正常。将解决方法记录下来给需要的人。

//只需要在 HttpWebRequest 发送请求前加入下面的代码
ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;//.Net 4.0版本使用下面代码
ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

参考网址:https://www.cnblogs.com/fogwang/p/14462711.html


http://www.mrgr.cn/news/5351.html

相关文章:

  • 【OpenCV】 中使用 Lucas-Kanade 光流进行对象跟踪和路径映射
  • 机器学习第五十三周周报 MAG
  • 集团数字化转型方案(七)
  • JVM常见面试题总结
  • 序列建模之循环和递归网络 - 优化长期依赖篇
  • 大白话社融中M1和M2的学习笔记
  • 基于SpringBoot的在线笔记网站的设计与实现
  • 探索深度学习的力量:从人工智能到计算机视觉的未来科技革命
  • 存在重复元素 II(LeetCode)
  • java在实际开发中反常识bug
  • 黑马头条vue2.0项目实战(十一)——功能优化(组件缓存、响应拦截器、路由跳转与权限管理)
  • 高并发eleme项目登录模块(thirty-three day)
  • ubuntu VCS+verdi安装遇到的一些问题
  • DFS - 树的重心
  • 网页,html,Web端实现RTSP/RTMP实时推流视频和播放
  • 不同版本gcc、g++的默认支持的std C++标准
  • 视频智能分析工业排污检测算法及算法源码全套应用方案
  • Rust web框架介绍一
  • 理解List AbstractList ArrayList
  • git常见问题