I have two different projects, one written in .Net 4.8 and another in .Net6.
The code works fine in .net 4.8, but fails in .net6. The exceptions I get, and it's inner exceptions, is
The SSL connection could not be established, see inner exception
Authentication failed, see inner exception
The token supplied to the function is invalid
The code is written in the same way, no difference at all. First the part for the System.Net.Http.HttpClient _httpRequestClient:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
string baseAddress = host;
string credentials = Convert.ToBase64String(new ASCIIEncoding().GetBytes(string.Format("{0}:{1}", connection.Username, connection.Password)));
_httpRequestClient = new HttpClient();
_httpRequestClient.BaseAddress = new Uri(baseAddress);
_httpRequestClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("basic",
credentials);
_httpRequestClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
And when making a call to the server from an async Task it throws the exeption:
using (var response = await _httpRequestClient.SendAsync(
new HttpRequestMessage(HttpMethod.Get, command), HttpCompletionOption.ResponseHeadersRead)
)
While debugging, the _httpRequestClient.DefaultRequestHeaders.Authorization is exactly the same in both projects (as well as most of the values) except that in .net6 the _httpRequestClient also has DefaultRequestVersion and DefaultVersionPolicy.
For now at least, I really cannot figure out what's wrong. Please help :)