i made a program, to retrieve some price from some website, it works pretty good, but if i let my application rest or idle for 1 or 2 minutes then when i want to run a price check againm it would throw an exception "an error occurred while sending the request"
, i have tried everything i found in google, like adding SecurityProtocol, running it on a Task
or using WebClient, but nothing works.
here is the function that retrieve my http code, i then extract the price from it.
HttpClient client = new HttpClient();
public async Task ListViewScanner(string URL, int SelectedItem)
{
string webData;
try
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 |
System.Net.SecurityProtocolType.Tls11 |
System.Net.SecurityProtocolType.Tls;
using (HttpResponseMessage response = await client.GetAsync(URL))
{
response.EnsureSuccessStatusCode();
webData = await response.Content.ReadAsStringAsync(); //HERE MY CATCH GETS TRIGGERED
}
}
catch (HttpRequestException e)
{
MessageBox.Show($"Message :{e.Message} ");
webData = "ERROR";
}
}
I commented where i get the exception.
exceptions
SocketException: An existing connection was forcibly closed by the remote host
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
WebException: The underlying connection was closed: An unexpected error occurred on a send.
HttpRequestException: An error occurred while sending the request.