I am trying to make a web request to microsoft.com (either http, https) in windows 11 succeeds but in windows server 2019 returns 403. Below, is the code:
var uri = new Uri("https://www.microsoft.com");
var request = (HttpWebRequest)WebRequest.Create(uri);
request.AllowAutoRedirect = true;
request.Method = "GET";
request.UserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64; Trident / 7.0; rv: 11.0) like Gecko";
request.Accept = "application/xml";
request.ContentType = "application/xml";
request.CookieContainer = new CookieContainer();
try
{
var response = (HttpWebResponse)request.GetResponse();
var webResponseStatusCode = response.StatusCode;
Console.WriteLine("it works - " + webResponseStatusCode);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadKey();
I also tried with the ServerCertificateValidationCallback callback if there was an error there, and also with different user agents the result is the same. I suspect that because the TLS1.3 is not supported in windows server 2019 it may cause this issue, but this is the issue then how can this fixed? (trying to enable the tls1.3 via registry keys made the VM not reachable with RDP).
Also only microsoft.com url I have found with the 403 error. Other url's like google.com returns 200 OK.
Any ideas?