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);
  • 相关阅读:
    数据结构:排序(1)
    日语分类系列:05
    数据结构:图(2)
    日语分类系列:04
    数据结构:图(1)
    日语分类系列:03
    数据结构:树
    django-restframework view中的内容
    django-restframework serializers文件的内容
    django-restframework settings 内设置及功能
  • 原文地址:https://www.cnblogs.com/Farmer-D/p/12986104.html
Copyright © 2011-2022 走看看