0

I'm trying to communicate with a server where I need to pass pfx cert, host and passphrase.

To test the server, I use Postman. So I fill the certificate setting in postman, and my request works fine as shown here.

enter image description here

I see there is a way to add pfx cert with password but how to add all 3 (host along with pfx cert and password)?

var client = new RestClient(url);
string certificatePath = @"certificates/certificate.pfx";
string pass = "password";

X509Certificate2 certificate = new X509Certificate2(certificatePath, pass);
client.ClientCertificates = new X509CertificateCollection() { certificate };
client.Proxy = new WebProxy();

var restrequest = new RestRequest(Method.POST);
restrequest.AddHeader("Cache-Control", "no-cache");
restrequest.AddHeader("Accept", "application/json");
restrequest.AddHeader("Content-Type", "application/json");

IRestResponse response = client.Execute(restrequest);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
San jay
  • 5
  • 3
  • 1
    You don't have to, just use that RestClient for one domain. – CodeCaster Sep 23 '22 at 13:50
  • Sorry, I didn't understand. "just use that RestClient for one domain"? Do you mean passing pfx cert and passphrase is enough and we don't need to pass the hostname anywhere in restSharp? – San jay Sep 23 '22 at 13:58

1 Answers1

0

In PostMan, you configure the host so it doesn't use that certificate for communication with any host asking for a client certificate.

In your code, you can ensure that you use the RestClient that you configure with that certificate only for communication with a given host.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272