如何在restClient C#中使用证书

时间:2018-05-10 17:38:20

标签: c# ssl asp.net-web-api rest-client pfx

我有一个.pfx文件,我也基于.pfx文件生成.ct和.key ...

我可以使用Postman发出请求,但我无法从C#代码发送请求。 这是代码:

var client = new RestClient("https://example.org/api/Schema/findColumn?columnName=Form_Id&TableName=Form");
        var request = new RestRequest(Method.GET);
        request.AddHeader("Referer", "https://.org");
        request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        request.AddHeader("Upgrade-Insecure-Requests", "1");
        request.AddHeader("Cache-Control", "max-age=0");
        request.AddHeader("Connection", "keep-alive");
        request.AddHeader("Host", "abc.org");



        X509Certificate2 certificates = new X509Certificate2(@"F:\Certificate\cert-test.pfx", "123456");
        var t = new RSACryptoServiceProvider();



        client.ClientCertificates = new X509CertificateCollection() { certificates };

        IRestResponse response = client.Execute(request);

它说"底层连接已关闭:无法建立SSL / TLS安全通道的信任关系。"

0 个答案:

没有答案