C#-RestSharp-请求被中止:无法创建SSL/TLS安全通道

C#-RestSharp-请求被中止:无法创建SSL/TLS安全通道,c#,rest,restsharp,C#,Rest,Restsharp,我正在尝试使用RestSharp调用RESTWeb服务 以下是我的代码: ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11

我正在尝试使用RestSharp调用RESTWeb服务

以下是我的代码:

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.DefaultConnectionLimit = 9999;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
        ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

        var client = new RestClient(url);
        var certificate = new X509Certificate();

        certificate.Import(Properties.Resources.cert, "password", X509KeyStorageFlags.PersistKeySet);
        client.ClientCertificates = new X509CertificateCollection() { certificate };

        var request = new RestRequest(Method.POST);
        request.AddHeader("Connection", "keep-alive");
        request.AddHeader("Content-Type", "text/plain");
        request.AddParameter("undefined", $"param={param}", ParameterType.RequestBody);
        IRestResponse response = await client.ExecutePostTaskAsync(request);

        return response;
但是,我收到一个错误-请求被中止:无法创建SSL/TLS安全通道

我还尝试搜索此错误,但在所有帖子中,人们都建议使用-
SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue=true

我已经在代码中使用了这些,但仍然看到了错误。另外,如果我尝试使用Postman触发类似的请求,它也可以正常工作

还有什么我遗漏的吗

找到了。C#要求在用户存储中导入证书。 我错过了这一部分。 在将pfx导入到用户商店之后,对于第一个请求,系统会提示我允许操作系统的请求,随后的请求工作正常

找到了。C#要求在用户存储中导入证书。 我错过了这一部分。 在将pfx导入到用户商店之后,对于第一个请求,系统会提示我允许操作系统的请求,随后的请求工作正常