如何通过在C#中使用restclient在标头请求中通过ssl证书?

时间:2018-06-29 14:06:36

标签: c#

有人可以提供帮助,如何在C#中使用restclient在标头请求中通过ssl证书?

这是我的代码段。

ServicePointManager.Expect100Continue = true;
            ServicePointManager.DefaultConnectionLimit = 9999;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

            string certificate = AppDomain.CurrentDomain.BaseDirectory + GetConfigurationValue("ClientCertificatePath");
            X509Certificate2 certificates = new X509Certificate2();

            CommonLogger.Info("certificate path=" + certificate);
            //CommonLogger.Info("Cert before import 1" + certificates);
            //CommonLogger.Info("Cert nefore import 2" + certificates.GetRawCertDataString());
            certificates.Import(certificate, GetConfigurationValue("ClientCertificatePassword"), X509KeyStorageFlags.MachineKeySet);

            //CommonLogger.Info("Cert after import" + certificates.GetRawCertDataString());
            tmpServiceClient.ClientCertificates = new X509CertificateCollection() { certificates };
            tmpServiceClient.Proxy = new WebProxy();

0 个答案:

没有答案