gpt4 book ai didi

c# - RestSharp 如何在 Https 请求中添加客户端证书? (C#)

转载 作者:太空狗 更新时间:2023-10-29 17:33:08 25 4
gpt4 key购买 nike

RestSharp 如何在 Https 请求中添加客户端证书?我的代码不起作用。

    public static IRestResponse<User> 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<User> response = client.Execute<User>(request);

return response;

}

最佳答案

首先你应该导入证书,然后附加到请求

X509Certificate2 certificate = new X509Certificate2();
certificates.Import(...);

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

关于c# - RestSharp 如何在 Https 请求中添加客户端证书? (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com