Unable to get C# RestSharp Query with PEM certificate to work

Viewed 191

I am trying to get a Restsharp query to work but cannot get the connection to work, the endpoint keeps saying that the SSL connection could not be established. Is the below code correct for sending a certificate with a call?

using System;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using RestSharp;

namespace APICALL
{
    class Program
    { 
        static void Main()
        {
            var client = new RestClient("https://placewherethecallisgoing.com");

            X509Certificate2 certificate = new (X509Certificate2.CreateFromPemFile("C://certificatefilepath//certificate.pem", "C://keyfilepath//keyfile.key"));
            client.ClientCertificates = new X509Certificate2Collection(){ certificate };
            client.Timeout = -1;

            var request = new RestRequest(Method.POST);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", "{\"query\":\"\",\"variables\":{}}",ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            Console.WriteLine("API Response:" + response.Content);
        }
    }
}

Any help with this would be greatly appreciated.

0 Answers
Related