Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with user1672994's answer chosen by CommunityBot
Notice added Authoritative reference needed by Somnath Kadam
Bounty Started worth 50 reputation by Somnath Kadam
error added
Source Link
Somnath Kadam
  • 6.5k
  • 6
  • 27
  • 37

Want to send data with client certificate (.p12 or .pfx) from Windows application to Server machine, Windows application developed in .Net Framework 4.6, OS is windows 10.

When hit from postman with client certificate (.p12 or .pfx) [Loaded in setting tab -> Add client certificate - > put hostname, select pfx file, put password], all working properly (client certificate send to server machine), but issue from below c# code,

X509Certificate2 certificate = new X509Certificate2(certificateFilePath, "password"); WebRequestHandler handler = new WebRequestHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ServerCertificateValidationCallback = (a, b, c, d) => { return true; }; handler.ClientCertificates.Add(certificate); HttpClient request = new HttpClient(handler); request.DefaultRequestHeaders.Add("User-Agent", UserAgent); // added other headers and data var result = request.PostAsync(url, byteContent).Result; string resultContent = result.Content.ReadAsStringAsync().Result; 

Also cross check with fiddler for Postman hit and c# hit.

When server not receive client certificate, it return 403 error.

Want to send data with client certificate (.p12 or .pfx) from Windows application to Server machine, Windows application developed in .Net Framework 4.6, OS is windows 10.

When hit from postman with client certificate (.p12 or .pfx) [Loaded in setting tab -> Add client certificate - > put hostname, select pfx file, put password], all working properly (client certificate send to server machine), but issue from below c# code,

X509Certificate2 certificate = new X509Certificate2(certificateFilePath, "password"); WebRequestHandler handler = new WebRequestHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ServerCertificateValidationCallback = (a, b, c, d) => { return true; }; handler.ClientCertificates.Add(certificate); HttpClient request = new HttpClient(handler); request.DefaultRequestHeaders.Add("User-Agent", UserAgent); // added other headers and data var result = request.PostAsync(url, byteContent).Result; string resultContent = result.Content.ReadAsStringAsync().Result; 

Also cross check with fiddler for Postman hit and c# hit.

Want to send data with client certificate (.p12 or .pfx) from Windows application to Server machine, Windows application developed in .Net Framework 4.6, OS is windows 10.

When hit from postman with client certificate (.p12 or .pfx) [Loaded in setting tab -> Add client certificate - > put hostname, select pfx file, put password], all working properly (client certificate send to server machine), but issue from below c# code,

X509Certificate2 certificate = new X509Certificate2(certificateFilePath, "password"); WebRequestHandler handler = new WebRequestHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ServerCertificateValidationCallback = (a, b, c, d) => { return true; }; handler.ClientCertificates.Add(certificate); HttpClient request = new HttpClient(handler); request.DefaultRequestHeaders.Add("User-Agent", UserAgent); // added other headers and data var result = request.PostAsync(url, byteContent).Result; string resultContent = result.Content.ReadAsStringAsync().Result; 

Also cross check with fiddler for Postman hit and c# hit.

When server not receive client certificate, it return 403 error.

Source Link
Somnath Kadam
  • 6.5k
  • 6
  • 27
  • 37

Client certificate with HttpClient in c#

Want to send data with client certificate (.p12 or .pfx) from Windows application to Server machine, Windows application developed in .Net Framework 4.6, OS is windows 10.

When hit from postman with client certificate (.p12 or .pfx) [Loaded in setting tab -> Add client certificate - > put hostname, select pfx file, put password], all working properly (client certificate send to server machine), but issue from below c# code,

X509Certificate2 certificate = new X509Certificate2(certificateFilePath, "password"); WebRequestHandler handler = new WebRequestHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.ServerCertificateValidationCallback = (a, b, c, d) => { return true; }; handler.ClientCertificates.Add(certificate); HttpClient request = new HttpClient(handler); request.DefaultRequestHeaders.Add("User-Agent", UserAgent); // added other headers and data var result = request.PostAsync(url, byteContent).Result; string resultContent = result.Content.ReadAsStringAsync().Result; 

Also cross check with fiddler for Postman hit and c# hit.