Skip to content

Instantly share code, notes, and snippets.

@belem2050
Last active April 8, 2025 08:11
Show Gist options
  • Save belem2050/6e60d364cfd46299c223496c2d710dbb to your computer and use it in GitHub Desktop.
Save belem2050/6e60d364cfd46299c223496c2d710dbb to your computer and use it in GitHub Desktop.
HTTP webserver client
class Program
{
static async Task Main(string[] args)
{
string url = "https://192.168.31.120:443/x";
int sleepDelqay = 500; //ms
HttpClientHandler handler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
};
using (HttpClient client = new HttpClient(handler))
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls13;
client.Timeout = TimeSpan.FromSeconds(30);
int i = 1;
while(true)
{
try
{
DateTime start = DateTime.Now;
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"Elapsed Time {DateTime.Now.Subtract(start).TotalMilliseconds} ms ");
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Resquest #{i}");
Console.WriteLine($"Response: {content}");
Console.WriteLine($"Sleep {sleepDelqay} ms ");
await Task.Delay(sleepDelqay);
i++;
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
//Console.ReadKey();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment