RestSharp 并忽略 SSL 证书中的错误

Aag*_*nor 5 rest ssl restsharp

我尝试在显然没有有效 ssl 证书的服务器上使用 RestSharp 启动 REST 请求,因为我收到错误

底层连接已关闭:无法建立 SSL/TLS 安全通道的信任关系。

我发现了这个问题,但提供的解决方案,虽然看起来很简单,但不起作用,我仍然收到错误。这是我的代码,有什么想法可能有问题吗?

private void Test_REST()
{
  var client = new RestClient("https://online.gema.de");

  // both versions not working
  ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
  client.RemoteCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

  // execute the request
  IRestResponse response = client.Execute(GEMA_Authorize());
  var content = response.Content; // raw content as string
}

private RestRequest GEMA_Authorize()
{
  RestRequest request = new RestRequest("api/v1/authorize", Method.GET);
  request.AddParameter("response_type", "token"); 
  request.AddParameter("client_id", "test_client");
  request.AddHeader("Accept", "application/json");
  request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

  return request;
}
Run Code Online (Sandbox Code Playgroud)

当我这样写回调时:

  .ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
  {
    return true;
  };
Run Code Online (Sandbox Code Playgroud)

并且在执行时设置断点return true;并不会在那里停止,所以看起来回调永远不会被回调。有什么想法可能是什么问题吗?我对 REST 还很陌生,所以我可能会错过一些重要的东西。

预先感谢,
弗兰克

jfm*_*fmg 3

的用法

client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
Run Code Online (Sandbox Code Playgroud)

为我工作。