Good morning everyone,
we have a problem concerning the consumption of a REST service via POST call, which works with Postman from the machine itself, from a Windows Server 2012 R2 and .NET Framework 4.8 server with TLS 1.2.
The error returned is this:
The request was aborted: Could not create SSL / TLS secure channel.
at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult, TransportContext & context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback (IAsyncResult ar)
Instead, the code is this:
ServicePointManager.SecurityProtocol | = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
using (HttpClient client = new HttpClient ())
{
client.BaseAddress = new Uri (this.Settings.Request.BaseAddress);
if (this.Settings.Authentication.Required)
{
byte [] bytes = Encoding.ASCII.GetBytes (this.Settings.Authentication.UserName + ":" + this.Settings.Authentication.Password);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue ("Basic", Convert.ToBase64String (bytes));
}
client.DefaultRequestHeaders.Accept.Add (new MediaTypeWithQualityHeaderValue ("application / json"));
string jsonContent = File.ReadAllText (file.FullName, encoding);
this.Logs.Add ("Sending the file:" + jsonContent, false);
StringContent content = new StringContent (jsonContent, encoding, "application / json");
HttpResponseMessage response = await client.PostAsync (this.Settings.Request.Endpoint, content);
if (response.IsSuccessStatusCode)
{
ResponseResult responseResult = JsonSerializer.Deserialize <ResponseResult> (response.Content.ReadAsStringAsync (). Result);
switch (responseResult.ResponseType)
{
case ResponseResult.eResponseType.OK:
this.Logs.Add ("File" + file.Name + "sent successfully:" + responseResult.detail, false);
break;
case ResponseResult.eResponseType.KO:
internalResult.SetError (responseResult.detail, (eTypeResult) 8);
this.Logs.Add ("File" + file.Name + "not sent:" + responseResult.detail, true);
break;
case ResponseResult.eResponseType.WARNING:
this.Logs.Add ("File" + file.Name + "sent (WARNING)
: "+ responseResult.detail, false);
break;
}
}
else
{
string responseContent = await response.Content.ReadAsStringAsync ();
if (string.IsNullOrWhiteSpace (responseContent))
{
responseContent = response.ToString ();
}
internalResult.SetError (responseContent, (eTypeResult) 8);
}
}
The exact same software works on Windows Server 2016.
We have tried to change the various registry keys as indicated in the different documents found online, but nothing changes and the error remains.
We would like to understand if there is some way to manage this connection on Server 2012 R2 or not.
Thank you,
Marco Tomatis