C# HttpClient status code

C# HttpClient status code

 

HTTP response status codes provide whether a specific HTTP request has been successfully completed. Responses are grouped in five classes in following code:

 

  • Informational responses (100–199)
  • Successful responses (200–299)
  • Redirects (300–399)
  • Client errors (400–499)
  • Server errors (500–599)

 

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace usingcsharp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            using var client = new HttpClient();

            var results = await client.GetAsync("https://usingcsharp.com");
            Console.WriteLine(results.StatusCode);
        }
    }
}

2021-10-03