Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:42:07+00:00 2026-06-07T14:42:07+00:00

I previously had a small VBScript that would test if a specific website was

  • 0

I previously had a small VBScript that would test if a specific website was accessible by sending a GET request. The script itself was extremely simple and did everything I needed:

Function GETRequest(URL) 'Sends a GET http request to a specific URL
   Dim objHttpRequest

   Set objHttpRequest = CreateObject("MSXML2.XMLHTTP.3.0")
   objHttpRequest.Open "GET", URL, False

   On Error Resume Next 'Error checking in case access is denied
   objHttpRequest.Send

   GETRequest = objHttpRequest.Status
End Function

I now want to include this sort of functionality in an expanded C# application. However I’ve been unable to get the same results my previous script provided.

Using code similar to what I’ve posted below sort of gets me a proper result, but fails to run if my network connection has failed.

public static void GETRequest()
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://url");
    request.Method = "GET";
    HttpStatusCode status;
    HttpWebResponse response;
    try
    {
       response = (HttpWebResponse)request.GetResponse();
       status = response.StatusCode;
       Console.WriteLine((int)response.StatusCode);
       Console.WriteLine(status);
    }
    catch (WebException e)
    {
       status = ((HttpWebResponse)e.Response).StatusCode;
       Console.WriteLine(status);
    }
}

But as I said, I need to know if the site is accessible, not matter the reason: the portal could be down, or the problem might reside on the side of the PC that’s trying to access it. Either way: I don’t care.

When I used MSXML2.XMLHTTP.3.0 in the script I was able to get values ranging from 12000 to 12156 if I was having network problems. I would like to have the same functionality in my C# app, that way I could at least write a minimum of information to a log and let the computer act accordingly. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:42:09+00:00Added an answer on June 7, 2026 at 2:42 pm

    A direct translation of your code would be something like this:

    static void GetStatusCode(string url)
    {
        dynamic httpRequest = Activator.CreateInstance(Type.GetTypeFromProgID("MSXML2.XMLHTTP.3.0"));
        httpRequest.Open("GET", url, false);
    
        try     { httpRequest.Send(); }
        catch   { }
        finally { Console.WriteLine(httpRequest.Status); }
    }
    

    It’s as small and simple as your VBScript script, and uses the same COM object to send the request.

    This code happily gives me error code like 12029 ERROR_WINHTTP_CANNOT_CONNECT or 12007 ERROR_WINHTTP_NAME_NOT_RESOLVED etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I previously had a table that is created using hibernate entities. I am using
I previously had a post on this issue that was resolved. However since rebuilding
I have an application that uses CoreData. I previously had a class named Marker
Previously we had desktop applications but given the fact that accessing the server (either
previously i had custom tableviewcell and was loading from Nib.in that i have specified
When working on small projects or some test classes , I would prefer to
I've got a small website that has about 5-10 administrators. I've set it up
I previously had code that used File.ReadAllLines() to read a text file and store
I have a C# project that I previously had targeting .NET 4.0, and now
I have a webpage that previously had no doctype declaration. Now, I've added <!doctype

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.