HttpStatusCode class does not exist code 207, 208 and 226

5

What to do when the HttpStatusCode class does not exist the 207 , 208 and 226

Someone already asked the question in GitHub: link , it seems to me that they did not do an "update". Here is the code:

HttpResponseMessage response = await httpClient.PostAsync();
if ((int)response.StatusCode < 200 || (int)response.StatusCode > 226 && (int)response.StatusCode != 404) //[200,208] = HTTP OK
{
    //HTTP Response Not OK
}

In the above code you can only enter if when different from the list below.

Here is the "Success" family list:

  
  • 200
  •   
  • 201
  •   
  • 202
  •   
  • 203
  •   
  • 204
  •   
  • 205
  •   
  • 206
  •   
  • 207
  •   
  • 208
  •   
  • 226
  •   

    Source list: link

        
    asked by anonymous 04.09.2018 / 17:39

    2 answers

    4

    Successful is not only the range that you display, it ranges from 200 to 299, you can validate through the IsSuccessStatusCode property of the HttpResponseMessage class.

    HttpResponseMessage response = await httpClient.PostAsync();
    if (!response.IsSuccessStatusCode)
    {
        //HTTP Response Not OK
    }
    

    #

    04.09.2018 / 18:26
    0

    You can also use the System.Net library, it contains an enumerator named HttpStatusCode and you can compare the results, rather than using magic numbers. >

    HttpResponseMessage response = await httpClient.PostAsync();
    if ((int)response.StatusCode < (int)HttpStatusCode.NotFound)
    
        
    04.09.2018 / 19:04