Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
1.2k views
in .Net Framework by 14 22 29

I'm working on an application in C# that checks the status code of the websites so I need to get the status code for each given website.

This is the output of the HTTP status code that I need to get in C#.

How to get HTTP status code in C#?


1 Answer

0 like 0 dislike
by 14 22 29

Get HTTP status code of a website in C#

  1. First, you need to use System.Net namespace then create a web request to the website

     using System.Net;
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“https://debug.to”);
    
  2. After creating a web request then you need to get the response for that site request

     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
  3. Now you can get the status code for that response

     HttpStatusCode statusCode = response.StatusCode;
     Console.Write(“Status Code: ”+ (int)statusCode + “ ”+ statusCode);
    

See Also

If you don’t ask, the answer is always NO!
...