您可以添加一個客戶端證書,以這樣的Web請求。
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "XYZ", true);
X509Certificate2 certificate = certificates[0];
HttpWebRequest request = new HttpWebRequest();
request.ClientCertificates.Add(certificate);
注:WebRequest
已過時。
嘗試使用HttpClient的替代,這將看看什麼是您使用REST客戶端這樣的事情
X509Store store = new X509Store("My", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "XYZ", true);
X509Certificate2 certificate = certificates[0];
WebRequestHandler handler = new WebRequestHandler();
handler.ClientCertificates.Add(certificate);
HttpClient client = new HttpClient(handler);
? – Alex
它是一個網絡API,我現在用的HttpWebRequest – Techie
http://stackoverflow.com/questions/23451024/webrequest-not-sending-client-certificate – Alex