I am communicating with a server that uses mutual TLS v1.2. I have been able to make this request in a c# console application, but when I copy this exact code to Xamarin forms, my RestClient gives me an exception: "Connection reset by peer" after a few seconds.
The code:
var client = new RestClient("https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts"); ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; client.ClientCertificates = new X509CertificateCollection() { certificate }; client.Proxy = new WebProxy(); var request = new RestRequest(Method.GET); var response = client.Execute(request); Console.WriteLine(response.StatusCode); Console.WriteLine(response.Content);
I am unable to share my API keys and such, for obvious reasons. These are added through headers and are removed from the code snippet.
Things I have tried:
Answers
@Luca.9439
It's hard to tell reason with such limited info.
I think it may be caused by the certificate. And what's the version of
RestSharp
are you using? Is it the latest one?It's better you could provide a demo which can reproduce the issue. Then we can help you solve this problem.
I don't think it's caused by the certificate, because it works perfectly fine in a console application. I'm using the latest version of RestSharp btw.
I did some more digging, and it seems to be something inside of mono. Since it works in .NET (the console app), but not in the mobile app (mono). There is a property on HttpWebRequest that is called version, you can set this one to one of the options from the HttpVersion enum. But this enum only contains version 10 and 11, not 12. I'm not sure if RestSharp uses the HttpWebRequest class, but if I cant use version 12, they shouldn't be able to either. So I think the issue is somewhere there.
If you want, you can add me on skype or discord so I can send some working code. (PM for the contact details)