gpt4 book ai didi

C# Web 请求 w RestSharp - "The request was aborted: Could not create SSL/TLS secure channel"

转载 作者:太空狗 更新时间:2023-10-29 20:19:18 27 4
gpt4 key购买 nike

我有一个使用 RestSharp 的非常简单的 Web 请求:

var client = new RestClient("https://website.net");
var request = new RestRequest("/process", Method.GET);
request.AddParameter("cmd", "execute");
IRestResponse response = client.Execute(request);

var content = response.Content;
Console.WriteLine("Response: " + content);

这将返回错误消息:

The request was aborted: Could not create SSL/TLS secure channel

三件事:

  1. 我通过浏览器得到了我期望的响应,
  2. 我通过 Postman 得到了我期望的响应,
  3. 此请求正在发送到测试环境,但我可以将其发送到具有非常相似地址的生产环境,并获得我期望的响应,
  4. 我确信它在今天之前有效。

他们的证书使用 TLS 1.2 和 AES 128,因此它与 RC4 引起的错误无关。

这是在我的 Visual Studio 2015 本地 Win 10 机器上,目标框架是 .NET 4.5.2。

为什么会出现此错误?

编辑:

通过更改我的代码以使用基本 System.Net 和 WebRequest 类并添加以下行:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

根据 here 的建议, 有用。所以我猜 RestSharp 出于某种原因使用了不正确的协议(protocol)?

最佳答案

.NET 4.5 中,TLS 1.2 可用不可用 em> 默认启用。

是的,如果您需要 TLS 1.2,您需要以某种方式为 .NET 运行时指定它。

仅供引用:在 .NET 4.7 中,.NET 将使用操作系统的默认 SSL/TLS 版本(大多数现代操作系统将默认使用 TLS 1.2)


其他好的SO回答:

Default SecurityProtocol in .NET 4.5

关于C# Web 请求 w RestSharp - "The request was aborted: Could not create SSL/TLS secure channel",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49885842/

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