0

As I said in title, I have an ASP.NET Core 3.1 MVC app that is trying to request outer API (onetrust api). It is perfectly running on my localhost. But when my supervisor deployed it to server, we are not getting answer. I have no server access because I'm working as intern. I would be appreciate to any suggestion.

This is my code for the API request from ASP.NET Core MVC:

var client = new RestClient("myUrl");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Cookie", "thisIsCookieKey");
request.AlwaysMultipartFormData = true;
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", this._clientId);
request.AddParameter("client_secret", this._clientSecret);
IRestResponse response = client.Execute(request);
return JsonConvert.DeserializeObject<Token>(response.Content);

The server log is for error is: The SSL connection could not be established, see inner exception. Authentication failed, see inner exception. error expection:System.Net.WebException: The SSL connection could not be established, see inner exception. Authentication failed, see inner exception.

My supervisor said we've got ssl licesce. What else should I do to solve this error?

By the way I am using resharp client tool to request api. Thanks

  • What's the error message? – Sekhar Jun 16 '21 at 06:47
  • it is " The SSL connection could not be established, see inner exception. Authentication failed, see inner exception. error expection:System.Net.WebException: The SSL connection could not be established, see inner exception. Authentication failed, see inner exception." My boss said that we've got the ssl for app, what else should we do? – Cumali Toprak Jun 16 '21 at 09:56
  • I think your system is using TLS1.2 by default, but your supervisor's system is not. Add this line in the beginning of the code. `System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;` – Sekhar Jun 16 '21 at 11:49
  • I added the code beginning of where I request from, but it didn't work. Then added it to main method that was also didn't work, gave me same error. Nothing is changed actually. – Cumali Toprak Jun 16 '21 at 12:24

1 Answers1

0

This should work:

        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;//or change it to System.Net.SecurityProtocolType.Tls11 to test
        var client = new RestClient("myUrl");
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Cookie", "thisIsCookieKey");
        request.AlwaysMultipartFormData = true;
        request.AddParameter("grant_type", "client_credentials");
        request.AddParameter("client_id", this._clientId);
        request.AddParameter("client_secret", this._clientSecret);
        IRestResponse response = client.Execute(request);
        return JsonConvert.DeserializeObject<Token>(response.Content);
Sekhar
  • 5,614
  • 9
  • 38
  • 44
  • I tried it but didn't work on the server. Then, when I add the code like you sad but with tls11 it gave me the same error on my local machine that was I getting on server. What do you think about this? – Cumali Toprak Jun 17 '21 at 12:46
  • Sorry I misread the error message.. you can check if the client_credentials(id and secret) are still valid or not., you could also handle some custom SSL validation like this: https://stackoverflow.com/questions/54297514/how-to-fix-the-ssl-connection-could-not-be-established-see-inner-exception-w – Sekhar Jun 17 '21 at 13:37
  • Thanks for your help, I tried all of them but didn't work. – Cumali Toprak Jun 18 '21 at 08:27