Restsharp using ssl certificate

Asked

Viewed 1,135 times

3

Need to use certificate to connect to a server https with restsharp. I’m using this code:

var client = new RestClient(url);
client.ClientCertificates = new X509CertificateCollection();
client.ClientCertificates.Add(GetCertificado());

var request = new RestRequest("authorisationTransaction", Method.POST);
request.AddHeader("Content-type", "application/json; charset=utf-8");
request.AddHeader("Accept", "application/json");
request.RequestFormat = DataFormat.Json;

But I get the message:

The underlying connection was closed: Could not establish trust relationship for secure SSL/TLS channel.

To read the disk certificate I am using this method:

    private X509Certificate GetCertificado()
    {
        string Certificate = "certificado.cer";
        X509Certificate cert = new X509Certificate();
        cert.Import(Certificate);
        return cert;
    }

Any idea how to fix it ? Thank you!

  • From what I understand, this error may have a million causes, not necessarily related to something wrong in your code. I don’t have an answer for you, but I suggest that question and that other in Soen as starting points.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.