2 years ago

#47008

test-img

Joydeep Bhattacharya

Pfx certificate working in postman but throwing exception in C# code

I am trying to use a pfx certificate downloaded from azure portal, when I use the certificate to make the same call using postman it works fine, but when I try from the application I am getting the below exception.

InnerException: {"The credentials supplied to the package were not recognized"}

Message: "The SSL connection could not be established, see inner exception."

Here is my code for reference:

string thumbprint = "<some thumbprint>";
X509Certificate2 ClientCert = new CertificateHelpers().FindCertificates(thumbprint)[0];
            
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(ClientCert);
HttpClient Client = new HttpClient(handler)
{
    BaseAddress = new Uri("https://baseurl.com:8443")
};

string req = "/v1.0/some/api/call";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, req);
Task<HttpResponseMessage> responseMessage = Client.SendAsync(request);
Console.WriteLine(responseMessage.Result.StatusCode);

Any help is really appreciated, thanks in advance.

c#

.net

httpclient

x509certificate2

pfx

0 Answers

Your Answer

Accepted video resources