Trying to Request API with certificate Authentication Need Help How to load a Certificate in Http Request ?

Hi everyone am trying to Integrate a API to Post some data from NAV and Receive. For that to work  first need the Connection 

While Requesting i have needed to load Certificate which supplied to me and Call  for Request. I got Code for Username and Password Authentication, After Searching a lot on Web got the Below code load certificate but am getting a Error.

For reference i have seen this https://www.codeproject.com/Articles/426121/Send-a-private-client-certificate-p-in-HTTP-Post

HttpWebRequest := HttpWebRequest.Create('https://Website/api/Sign');
//VarTimeout := 50000;//Communication Timeout;
HttpWebRequest.Method := 'POST';
HttpWebRequest.ContentType := 'text/json';
HttpWebRequest.Accept := 'text/json';

X509Certificate2(@"E:\Certificate\clientcertificate.p12", "password"));
// /
X509cert := X509cert.X509Certificate2('C:\Users\r.raja\Pictures\CerttificateName.pfx','Password');//Getting Error here
HttpWebRequest.ClientCertificates.Add(X509cert);
HttpWebResponse := HttpWebRequest.GetResponse();

 

 

 

Error Says Like Below

 

Microsoft Dynamics NAV
---------------------------

A call to System.Security.Cryptography.X509Certificates.X509Certificate2 failed with this message: An error occurred during encode or decode operation.

---------------------------
OK
---------------------------

Related