title: Add certificate on request with RestSharp
body: <p>I'm trying to communicate with a server. This server send me a certificate and a private key in order to execute my request successfully.</p>
  
  <p>To test the server, I use <a href="https://www.getpostman.com/" rel="noreferrer">Postman</a>.
  So I fill the certificate setting in postman, and my request works fine</p>
  
  <p><a href="https://i.stack.imgur.com/j6BsC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/j6BsC.png" alt="Postman settings for certificates"></a></p>
  
  <p>Now I want to do the same in C#.</p>
  
  <p>For that I use <a href="http://restsharp.org/" rel="noreferrer">RestSharp</a> in order to create the request. </p>
  
  <p>Here is my code</p>
  
  <pre><code> var client = new RestClient(url);
  
   byte[] certBuffer = UtilsService.GetBytesFromPEM(myCertificate, Models.Enum.PemStringType.Certificate);
   byte[] keyBuffer = UtilsService.GetBytesFromPEM(encryptedPrivateKey, Models.Enum.PemStringType.RsaPrivateKey);
  
   X509Certificate2 certificate = new X509Certificate2(certBuffer, secret);
   client.ClientCertificates = new X509CertificateCollection() { certificate };
   var request = new RestRequest(Method.POST);
   request.AddHeader("Cache-Control", "no-cache");
   request.AddHeader("Accept", "application/json");
   request.AddHeader("Content-Type", "application/json");
   request.AddParameter("myStuff", ParameterType.RequestBody);
   IRestResponse response = client.Execute(request);
  </code></pre>
  
  <p>The request doesn't work. I think the problem is from how I load the certificate in RestSharp. </p>
  
  <p>I'm looking for information how to set correctly the certificate in RestSharp.</p>
  
  <p>I'm using RestSharp, but I could be anything else that can work in C#</p>