CopyCode The Code is as follows: Private void page_load (Object sender, system. eventargs E)
{
String url1 = "http://s.jb51.net /";
String url2 = "http://www.jb51.net/images/logo.gif ";
Response. Write ("<li> Method 1 :");
Response. Write (url1 + ":" + urlexistsusinghttpwebrequest (url1). tostring ());
Response. Write ("<li> Method 2 :");
Response. Write (url1 + "exist:" + urlexistsusingsockets (url1). tostring ());
Response. Write ("<li> method 3 :");
Response. Write (url1 + "exist:" + urlexistsusingxmlhttp (url1). tostring ());
Response. Write ("<li> Method 1 :");
Response. Write (url2 + ":" + urlexistsusinghttpwebrequest (url2). tostring ());
Response. Write ("<li> method 3 :");
Response. Write (url2 + "exist:" + urlexistsusingxmlhttp (url2). tostring ());
}
Private bool urlexistsusinghttpwebrequest (string URL ){
Try
{
System. net. httpwebrequest myrequest = (system. net. httpwebrequest) system. net. webrequest. Create (URL );
Myrequest. method = "head ";
MySQL request. Timeout = 100;
System. net. httpwebresponse res = (system. net. httpwebresponse) myrequest. getresponse ();
Return (res. statuscode = system. net. httpstatuscode. OK );
}
Catch (system. net. webexception we)
{
System. Diagnostics. Trace. Write (We. Message );
Return false;
}
}
private bool urlexistsusingxmlhttp (string URL)
{< br> // Note: msxml2.dll
msxml2.xmlhttp _ XMLHTTP = new msxml2.xmlhttpclass () must be referenced in this method ();
_ XMLHTTP. open ("head", URL, false, null, null);
_ XMLHTTP. send ("");
return (_ XMLHTTP. status = 200);
}< br> private bool urlexistsusingsockets (string URL)
{< br> If (URL. startswith ("http: //") url = URL. remove (0, "http ://". length);
try
{< br> system. net. iphostentry iphost = system. net. DNS. resolve (URL);
return true;
}< br> catch (system. net. sockets. socketexception SE)
{< br> system. diagnostics. trace. write (SE. message);
return false;
}< BR >}