如何以编程方式从需要来自智能卡的客户端证书的c#调用https端点?
我可以使用商店证书吗?还是需要将所需的证书导出到文件?
我可以在没有浏览器任何问题的情况下访问端点,但是当我从c#或节点执行此操作时,我获得401未授权,我使用存储或从文件导入证书尝试了两个选项,但这对我不起作用。< / p>
以下是示例代码:
const string url = "https://somesite.com/url";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
var certs = store.Certificates;
//var cert = new[] { X509Certificate.CreateFromCertFile("./m102044.cer") }; from cert exported from chrome
var request = (HttpWebRequest)WebRequest.Create(url);
request.ClientCertificates = certs;
var response = request.GetResponse(); // 401 unauthorized