.Net Framework: 4.8 Windows Server: 2012
Below code written in Console Application while i ran simple it's working fine. But when i schedule same console application in Task Scheduler it's Throwing Error.
The underlying connection was closed. An Existing connection was forcibly close by Remote Host
handler.ClientCertificates.Add(new X509Certificate2(CertificateFile, PassPhrase));
var client = new HttpClient(handler);
var authToken = Encoding.ASCII.GetBytes($"{USERNAME}:{PASSWORD}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
var requestContent = new StringContent("", Encoding.UTF8, "application/json");
var response = client.PostAsync(RestAPIURL, requestContent).Result;
response.EnsureSuccessStatusCode();
Log.WriteLog(response.ToString());
resData = response.Content.ReadAsStringAsync().Result;
resData.WriteResponse(); ```