C# 如何将PFX安装的证书添加到Windows.Web.Http.HttpClient

C# 如何将PFX安装的证书添加到Windows.Web.Http.HttpClient,c#,uwp,httpclient,pfx,C#,Uwp,Httpclient,Pfx,我已将pfx扩展证书手动安装到我的机器上。如何获取和传递Windows.Web.Http.HttpClient 我试着顺着这条路走,但没有成功 var myFilter = new HttpBaseProtocolFilter(); CertificateQuery certQuery = new Windows.Security.Cryptography.Certificates.CertificateQuery(); certQuery.FriendlyName =

我已将pfx扩展证书手动安装到我的机器上。如何获取和传递Windows.Web.Http.HttpClient

我试着顺着这条路走,但没有成功

    var myFilter = new HttpBaseProtocolFilter();
    CertificateQuery certQuery = new Windows.Security.Cryptography.Certificates.CertificateQuery();
    certQuery.FriendlyName = "TEST";    // This is the friendly name of the certificate that was just installed.
    IReadOnlyList<Certificate> certificates = await Windows.Security.Cryptography.Certificates.CertificateStores.FindAllAsync(certQuery);
    var client = new HttpClient(certificates[0]);
var myFilter=new-HttpBaseProtocolFilter();
CertificateQuery=新的Windows.Security.Cryptography.Certificates.CertificateQuery();
certQuery.FriendlyName=“测试”//这是刚安装的证书的友好名称。
IReadOnlyList certificates=等待Windows.Security.Cryptography.certificates.CertificateStores.FindAllAsync(certQuery);
var client=新的HttpClient(证书[0]);
有人能帮我在httpclient中添加手动安装的证书吗

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(
    X509FindType.FindByIssuerName, "TEST", false); 
    //Change FindType to your liking, it doesn't support FriendlyName, 
    //maybe use your method?

WebRequestHandler handler = new WebRequestHandler();
X509Certificate2 certificate = GetMyX509Certificate();
handler.ClientCertificates.Add(certificate);
HttpClient client = new HttpClient(handler);

给你。可能将您的证书用于Add方法,但我不知道它们是否兼容。

不是system.net.httpclient,而是用于UWP Windows.Web.Http.httpclient