2

I have a .crt file and a .key file which I have to send with my rest call using C#. Everywhere I am finding answers where it has been suggested to turn those files into a single .pfx file but the problem is that the server does not accept pfx. It accepts either .pem or needs both .crt and .key files. Is it really possible to send a .pem file along with a get call using RestSharp?I tried to use the following code but the response always says "connection denied by ACL". Thanks in advance for any kind of help.

`

var client = new RestClient(@"https://midway-itg-stage.glb1.hpe.com/files/storeeasy/");

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

            string certFile = @"C:\test_openssl.pem";
            X509Certificate2 certificate = new X509Certificate2(certFile,"file");
            client.ClientCertificates = new X509CertificateCollection() { certificate };
            //client.Proxy = new WebProxy();
            var restrequest = new RestRequest(Method.GET);
            //restrequest.AddHeader("Cache-Control", "no-cache");
            restrequest.AddHeader("Accept", "application/json");
            restrequest.AddHeader("Content-Type", "application/json");
            IRestResponse response = client.Execute(restrequest);
            Console.WriteLine(JsonConvert.SerializeObject(response));
            Console.WriteLine();
            Console.WriteLine();
            return response.Content;`
  • 1
    Possible duplicate of [Add certificate on request with RestSharp](https://stackoverflow.com/questions/49069197/add-certificate-on-request-with-restsharp) – n0idea Feb 15 '19 at 14:40
  • How do you know the server does not accept pfx ? – Thordax Jul 09 '20 at 08:52

0 Answers0