亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# - RestSharp - 請求已中止:無法創建 SSL/TLS 安全通道

C# - RestSharp - 請求已中止:無法創建 SSL/TLS 安全通道

C#
慕俠2389804 2023-08-20 14:53:17
我正在嘗試使用 RestSharp 調用 REST Web 服務。以下是我的代碼:        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 發出類似的請求,它工作得很好。我還缺少什么嗎?
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

找到了。C# 要求將證書導入到用戶存儲中。我錯過了這部分。將 pfx 導入用戶存儲后,對于第一個請求,操作系統提示我允許該請求,后續請求完美運行。



查看完整回答
反對 回復 2023-08-20
  • 1 回答
  • 0 關注
  • 770 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號