I'm trying to connect from a http client but if server is down for some reason I'm getting an exception while sending the request.
string Send = "Request";
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromMilliseconds(2000);
var response = await client.PostAsync("http://192.168.1.15:8282/", new StringContent(Send, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
MessageBox.Show(content);
}
}
Is there any method to check if server is not down. Also how can I set server connection timeout, Send request timeout and receive answer timeout?