2016-12-06 153 views
0

我有以下代碼使用基本身份驗證和SSL客戶端證書調用API,但其拋出異常並給我出現以下錯誤。請求已中止:無法創建SSL/TLS安全通道。 (RestSharp,SSL客戶端證書)

「請求已中止:無法創建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); 

回答

1

我也遇到過類似的問題。讓我在這裏提到你的幫助步驟。

安裝Windows服務後,我通過以下步驟去解決這個問題:

  • 轉到開始>運行,鍵入services.msc
  • 選擇服務>右鍵單擊並選擇屬性
  • 選擇第二選項卡「登錄」
  • 選擇單選按鈕「此帳戶」
  • 輸入用戶名和密碼登錄當前用戶。 (確保其誰已經安裝了該服務的相同用戶)
  • 應用更改
  • 啓動服務
+0

你指的是什麼樣的服務? – Para

相關問題