Detects if a URL address is responding

Source: Internet
Author: User

Today suddenly comes out a problem, URL address calls cause the program to die (because the service hangs, the disk is broken)

Then think of, and then call the URL address before the first to determine whether the address is a response, so that can not solve the problem?

C # code:

/// <summary>///detect if URL addresses are accessible/// </summary>/// <param name= "Url" >URL address (starting with HTTP//)</param>/// <returns>return to OK</returns>/// <example>isurlvist ("http://www.baidu.com")</example> Public Static stringIsurlvisit (stringUrl) {    stringRevlue =NULL; HttpWebRequest Request= (HttpWebRequest) webrequest.create (NewUri (URL)); Servicepointmanager.expect100continue=false; Try{(httpwebresponse) request. GetResponse ()).        Close (); Revlue="OK"; }    Catch(WebException ex) {Revlue=Ex.    ToString (); }    returnRevlue;}

Detects if a URL address is responding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.