Error SSL - Untrusted Root - V107.3.0

286 views
Skip to first unread message

Brendan Bell

unread,
Mar 31, 2022, 12:11:08 AM3/31/22
to RestSharp
Hi,

I'm using vs 2022 with .Net 6.0. Just trying a very simple example as a console app.

When using the following which is based on latest examples

```
var client = new RestClient("https://localhost:50000");
var request = new RestRequest("/b1s/v1/Login", Method.POST);
var Auth = new Model.SAP.Login { UserName = "username", Password = "password", CompanyDB = "database_name" };
request.AddJsonBody(Auth);
var response = await client.ExecutePostAsync(request);
Console.WriteLine(response.ToString());
```
I receive the following error:
The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot


When I use an older example, it works. This would be due to the  RemoteCertificateValidationCallback.

I'm trying to have the first example work, though i'm not sure how.

```
var client = new RestClient("https:// localhost:50000/b1s/v1/");
            client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
            client.Timeout = -1;

            var request = new RestRequest("Login", Method.POST);
            request.AddHeader("Content-Type", "application/json");
            var body = @"{
            " + "\n" +
                        @"    ""UserName"":""username"",
            " + "\n" +
                        @"    ""Password"":""password"",
            " + "\n" +
                        @"    ""CompanyDB"":""database_name""
            " + "\n" +
                        @"}";

            request.AddParameter("application/json", body, ParameterType.RequestBody);
            var response = client.Execute(request);
            Console.WriteLine(response.StatusCode);
```

Any feedback appreciated,

thank you
Reply all
Reply to author
Forward
0 new messages