RestSharp + Server Down - how do you know if the server is down?

I am wondering how I can check if the RestSharp request is called, which I made, because the server is not working, but something else.

When I turn off my server, I get the status code "NotFound", but it may not be found for a specific record (what I do on my site if I say that they are trying to find a record that can be deleted recently).

How can I understand that the server is actually not working?

Edit

here is my code

   private readonly RestClient client = new RestClient(GlobalVariables.ApiUrl);
          var request = new RestRequest("MyController", Method.POST);
                request.AddParameter("UserId", "1");
                request.AddParameter("Name", name.Trim());

                var asyncHandle = client.ExecuteAsync(request, response =>
                {
                    var status = response.StatusCode;
                });
+3
source share
3 answers

When the server is turned off, it should not return a "404 NotFound" error.

The most suitable in this case is HTTP Error 503 - service unavailable

- ( -) HTTP- - . , , . , - .

, RestResponse.StatusCode 503 , .

0

.

ContentLength. , web- ContentLength > 0 ( NotFound). , .

if ( response.StatusCode == System.Net.HttpStatusCode.NotFound &&
                response.ContentLength == -1 ){
   ==> client couldn't connect to webservice
}
0

, - , . , .. :

try
{
    var client = new RestClient(_configuration.ServerUrl);
    var request = new RestRequest
    {
        Resource = _configuration.SomeUrl,
        Method = Method.POST
    };

    var response = client.Execute(request);
    if (response.ErrorException != null)
    {
        throw response.ErrorException;
    }
}
catch (WebException ex)
{
    // TODO: check ex.Status, if it matches one of needed conditions.
} 

For more information about the WebExceptionStatus enumeration, see the following link https://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx

0
source

All Articles