Reputation: 13916
I need to invoke SSL enabled Web Api from a WinForm application. How do I configure HttpClient
for this?
These are the pre-requisites I have already completed:
RequireHttpsAttribute
.Upvotes: 1
Views: 278
Reputation: 8101
You can try yo use HttpClinet class with HttpClientHandler.
X509Certificate2 cert;
X509Store store = new X509Store(StoreName.My);
try
{
store.Open(OpenFlags.ReadOnly);
cert = store.Certificates.OfType<X509Certificate2>().First(p => p.Thumbprint == "...");
cert.Dump();
}
finally
{
if (store != null)
store.Close();
}
var clientHandler = new WebRequestHandler();
clientHandler.ClientCertificates.Add(cert);
var client = new HttpClient(clientHandler);
Upvotes: 1