如何在 Simple.OData.Client 中进行证书认证?我有 X509Certificate2 我想在调用 api 时使用它。我使用 .net 框架 4.6。
我做了一些搜索,我知道可以通过 HttpClientHandler 添加。但我无法弄清楚如何做到这一点。下面是我的代码。
void foo()
{
var clientSettings = new ODataClientSettings("");
clientSettings.OnApplyClientHandler = new Action<HttpClientHandler>(AddClientCertificate);
var client = new ODataClient(clientSettings);
}
private void AddClientCertificate(HttpClientHandler handler )
{
// I have working code to retrieve the certificate.
X509Certificate2 targetCertificate = RetrieveCertificate();
//TODO : Add the certificate to the HttpClientHandler
}