【问题标题】:The request was aborted: Could not create SSL/TLS secure channel. (RestSharp, SSL Client Certificates)请求被中止:无法创建 SSL/TLS 安全通道。 (RestSharp,SSL 客户端证书)
【发布时间】:2017-04-20 17:44:01
【问题描述】:

我有以下代码,它使用基本身份验证和 SSL 客户端证书调用 API,但它抛出异常并给我以下错误。

“请求中止:无法创建 SSL/TLS 安全通道。”

我试图在 Google 上找到解决方案,但没有找到任何解决方案。谁能帮我解决这个问题。谢谢。

// Variables 

string basicAuthenticationUserName = "username";
string basicAuthenticationPassword = "password";
string clientCertificateFilePath = "Path-To-Certificate-File";
string clientCertificatePassword = "certificate-password";
string url = "https://" + basicAuthenticationUserName + ":" + basicAuthenticationPassword + "@apiserverurl/apimethod";

// Creating RestSharp Request Object 

var request = new RestRequest(Method.POST)
{
    RequestFormat = DataFormat.Json,
    OnBeforeDeserialization = resp =>
    {
        resp.ContentType = "application/json";
    }
};

// Adding Headers

request.AddHeader("Content-Length", "0");
request.AddHeader("Accept", "application/x-null-message");

// Importing Certificates

var certificates = new X509Certificate();
certificates.Import(clientCertificateFilePath, clientCertificatePassword, X509KeyStorageFlags.PersistKeySet);

// Creating RestSharp Client Object

var client = new RestClient
{
    BaseUrl = new Uri(url),
    ClientCertificates = new X509CertificateCollection { certificates },
    Authenticator = new HttpBasicAuthenticator(managingLou, basicAuthenticationPassword)
};

// Executing Request 

var response = client.Execute<T>(request);

【问题讨论】:

    标签: authentication ssl certificate restsharp


    【解决方案1】:

    我也遇到过类似的问题。让我在这里提一下步骤以寻求帮助。

    安装windows服务后,我通过以下步骤解决了这个问题:

    • 转到开始 > 运行并键入 Services.msc
    • 选择您的服务 > 右键单击​​并选择属性
    • 选择第二个标签“登录”
    • 选择单选按钮“此帐户”
    • 输入当前登录用户的用户名和密码。 (确保是安装该服务的同一用户)
    • 应用更改
    • 启动服务

    【讨论】:

    • 你指的是什么服务?
    猜你喜欢
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2018-09-27
    • 2016-07-04
    • 2012-06-05
    相关资源
    最近更新 更多