How to RestSharp add client certificate in Https request? (C#)

匿名 (未验证) 提交于 2019-12-03 01:31:01

问题:

How to RestSharp add client certificate in Https request ? My code it doesn't work .

    public static IRestResponse AsyncHttpRequestLogIn(string path, string method, object obj)     {         var client = new RestClient(Constants.BASE_URL + path); // https:....         var request = method.Equals("POST") ? new RestRequest(Method.POST) : new RestRequest(Method.GET);         request.RequestFormat = RestSharp.DataFormat.Json;          // The path to the certificate.         string certificate = "cer/cert.cer";               client.ClientCertificates.Add(new X509Certificate(certificate));          request.AddBody(             obj         );           IRestResponse response = client.Execute(request);          return response;      } 

回答1:

At first you should import certificate and then attach to request

X509Certificate2 certificates = new X509Certificate2(); certificates.Import(...);  client.ClientCertificates = new X509CertificateCollection(){certificate}); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!