The requested security protocol is not supported

.Net Core访问https接口报错:The requested security protocol is not supported
W@O%1_%SR0LQ`Y1_Y~CFS%S.png

  1. HttpWebRequestreq = (HttpWebRequest)HttpWebRequest.Create(url);
  2. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3. //设置协议类型前设置协议版本
  4. req.ProtocolVersion = HttpVersion.Version11;
  5. //这里设置了协议类型。
  6. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
  7. ServicePointManager.CheckCertificateRevocationList = true;
  8. ServicePointManager.DefaultConnectionLimit = 1000;
  9. ServicePointManager.Expect100Continue = false;

The SSL connection could not be established, see inner exception

dotnet core在Linux(如:centOS)环境下使用HttpClient请求https可能会报异常:
One or more errors occurred. (The SSL connection could not be established, see inner exception.)
设置如下环境变量暂时解决:

  1. export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0

使用本地https证书

参考文章
.NetCore项目使用Https证书
.net core 配置安全证书及访问Https接口
asp.net core 2使用本地https证书