When calling the API from our production server, we get the following error:
The request was aborted: Could not create SSL/TLS secure channel. Stack
trace: at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult) at
System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
When we run the code locally using IIS Express in Visual Studio, the code works fine.
I understand that this might be an issue with the web host, but they seem clueless so I am checking here as well. Any help would be greatly appreciated.
By the way, adding the first line didn’t make any difference.
public async Task<List<Ticket>> FetchRecentTicketsAsync()
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
CNCSIMSERVERACCESS cNCSIMSERVERACCESS = new CNCSIMSERVERACCESS();
var apiKey = cNCSIMSERVERACCESS.GetVariable("FreshDeskAPIkey");
var oneWeekAgo = DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ssZ");
var apiUrl = "https://cncsimulator.freshdesk.com/api/v2/tickets?updated_since=" + oneWeekAgo;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(apiKey + ":X")));
var response = await client.GetAsync(apiUrl);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var tickets = JsonConvert.DeserializeObject<List<Ticket>>(content);
return tickets.Where(t => t.UpdatedAt >= DateTime.UtcNow.AddDays(-7) && t.Status == 2).ToList();
}
return null; // Handle errors appropriately.
}