zoukankan      html  css  js  c++  java
  • .Net Core 下 AWSSDK 中HTTPS请求的问题

    亚马逊S3的库在连接Https的对象存储时会返回:

    The remote certificate is invalid according to the validation procedure

    之前在.Net Framework中可以使用如下方式绕过SSL的验证:

    ServicePointManager.ServerCertificateValidationCallback
                           += RemoteCertificateValidate;
    
    private static bool RemoteCertificateValidate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {
         //TLS证书验证,直接返回成功
         return true;
    }

    但是这个方法在.Net Core中已经不管用了,在.Net Core中需要这样来处理:

    public class HttpClientFactoryAcceptAllSSL : Amazon.Runtime.HttpClientFactory
    {
            public override HttpClient CreateHttpClient(Amazon.Runtime.IClientConfig clientConfig)
            {
                System.Net.Http.HttpClientHandler handler = new System.Net.Http.HttpClientHandler();
                handler.ServerCertificateCustomValidationCallback = System.Net.Http.HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
                return new HttpClient(handler);
            }
    }
    AmazonS3Config config = new AmazonS3Config();
    config.ServiceURL = settings_.Value.OOS.ServiceURL;
    config.BufferSize = 100 * 1024;
    config.ForcePathStyle = true;
    config.Timeout = new TimeSpan(1, 0, 0);
    config.SignatureVersion = "2";
    config.HttpClientFactory = new HttpClientFactoryAcceptAllSSL();
    
    AmazonS3Client client = new AmazonS3Client(settings_.Value.OOS.AccessKeyId, settings_.Value.OOS.SecretAccessKey, config);
  • 相关阅读:
    读取csv遇到的双循环
    hadoop环境配置
    mysql的查询
    mysql的基本操作
    mysql与python的交互
    设置自动获取IP和DNS
    pyecharts绘制地图
    集合 set方法
    字符串 string方法
    字典 dict方法
  • 原文地址:https://www.cnblogs.com/Farmer-D/p/12986104.html
Copyright © 2011-2022 走看看