About "The SSL connection could not be established, see inner exception" issue in Windows Server 2012 R2

David Prasetya 6 Reputation points
2021-06-18T07:36:58.527+00:00

Hello there,

I currently working a web with ASP.NET Core.
I have an issue with deployed code in Windows Server 2012 R2.
Some code with task to take a data from certain endpoint did not work as expected (I use HttpWebRequest).
The code always return "The SSL connection could not be established, see inner exception" with inner exception "Authentication failed, see inner exception" with inner exception "The message received was unexpected or badly formatted".
I have tried it on local, and the code is working without any issue.
Is there anything I have to do for the code to be worked on the server?

This is the snipped code

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.KeepAlive = false;
 req.Method = "GET";
req.ContentType = "application/json";
req.MediaType = "application/json";
req.Accept = "application/json";
req.Headers.Add("apikey: " + Startup.user);
req.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
 responseFromServer = reader.ReadToEnd();
}

Let me know if I miss something for you to understand the questing.
Thanks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,059 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,518 questions
{count} vote

1 answer

Sort by: Most helpful
  1. 2022-07-06T10:56:28.603+00:00

    No I couldn’t

    0 comments No comments