I am trying to start a REST request with RestSharp on a server that obviously has no valid ssl certificate, as I get the error
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
I found this question but the provided solution, as simple as it may look doesn't work, I still get the error. Here is my code, any ideas what might be wrong?
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;
}
When I write the Callback like this:
.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
{
return true;
};
and set a breakpoint at return true;
the execution doesn't stop there, so it seems that the callback is never called back. Any ideas what might be the issue? I'm rather new to REST, so I might miss something crucial.
Thanks in advance,
Frank