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 8838829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:05:59+00:00 2026-06-14T10:05:59+00:00

I’m using a function to check if an external url exists. Here’s the code

  • 0

I’m using a function to check if an external url exists. Here’s the code with the status messages removed for clarity.

    public static bool VerifyUrl(string url)
    {
        url.ThrowNullOrEmpty("url");

        if (!(url.StartsWith("http://") || url.StartsWith("https://")))
            return false;

        var uri = new Uri(url);

        var webRequest = HttpWebRequest.Create(uri);
        webRequest.Timeout = 5000;
        webRequest.Method = "HEAD";

        HttpWebResponse webResponse;
        try
        {
            webResponse = (HttpWebResponse)webRequest.GetResponse();
            webResponse.Close();
        }
        catch (WebException)
        {
            return false;
        }

        if (string.Compare(uri.Host, webResponse.ResponseUri.Host, true) != 0)
        {
            string responseUri = webResponse.ResponseUri.ToString().ToLower();

            if (responseUri.IndexOf("error") > -1 || responseUri.IndexOf("404.") > -1 || responseUri.IndexOf("500.") > -1)
                return false;
        }

        return true;
    }

I’ve run a test over some external urls and found that about 20 out of 100 are coming back as errors. If i add a user agent the errors are around 14%.

The errors coming back are “forbidden”, although this can be resolved for 6% using a user agent, “service unavialable”, “method not allowed”, “not implemented” or “connection closed”.

Is there anything I can do to my code to ensure more, preferrably all give a valid response to their existance?

Altermatively, code that can be purchased to do this more effectively.

UPDATE – 14th Nov 12 ———————————————————————-

After following advice from previous respondants, I’m now in a situation where I have a single domain that returns Service Unavailable (503). The example I have is http://www.marksandspencer.com.

When I use this httpsniffer web-sniffer.net as opposed to the one recommended in this thread, it works, returning the data using a webrequest.GET, however I can’t work out what I need to do, to make it work in my code.

  • 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-14T10:06:00+00:00Added an answer on June 14, 2026 at 10:06 am

    I finally got to the point of bieng able to validate all the urls without exception.

    Firstly I took Davios advice. Some domains return an error on Request.HEAD so I have included a retry for specific scenarios. This created a new Request.GET for the second request.

    Secondly, the Amazon scenario. Amazon was intermittently returning a 503 error for its own site and permanent 503 errors for sites hosted on the Amazon framework.

    After some digging I found adding the following line to the Request resolved both. It is the Accept string used by Firefox.

    var request = (HttpWebRequest)HttpWebRequest.Create(uri);
    request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

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.