gpt4 book ai didi

authentication - 请求已中止 : Could not create SSL/TLS secure channel.(RestSharp、SSL 客户端证书)

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:45 25 4
gpt4 key购买 nike

我有以下代码使用基本身份验证和 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);

最佳答案

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

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

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

关于authentication - 请求已中止 : Could not create SSL/TLS secure channel.(RestSharp、SSL 客户端证书),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989379/

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