is there a way to check if a url or a website exists
Uri uri = new Uri("http://www.timvw.be");
HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest;
httpWebRequest.Method = "HEAD";
httpWebRequest.AllowAutoRedirect = true;
// we'll use the Async pattern...
httpWebRequest.BeginGetResponse(this.GetResponseCompleted, new object[] { httpWebRequest, uri });
private void GetResponseCompleted(IAsyncResult ar)
{
object[] objects = ar.AsyncState as object[];
HttpWebRequest httpWebRequest = objects[0] as HttpWebRequest;
Uri uri = objects[1] as Uri;
HttpWebResponse httpWebResponse = null;
int httpStatusCode;
try
{
httpWebResponse = httpWebRequest.EndGetResponse(ar) as HttpWebResponse;
httpStatusCode = (int)httpWebResponse.StatusCode;
}
catch (WebException webException)
{
httpWebResponse = webException.Response as HttpWebResponse;
if (httpWebResponse != null)
{
httpStatusCode = (int)httpWebResponse.StatusCode;
}
}
finally
{
if (httpStatusCode == 200 ) { Console.WriteLine("the resource exists"); }
if (httpWebResponse != null)
{
httpWebResponse.Close();
}
}
}
}
i've tried your code and it returns an exception
"Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )"
what is the meaning of this
'This code attempts to get a response from the passed URL.
Friend Function WebSiteIsAvailable(ByVal linkText As String) As Boolean Dim URL_Object As New System.Uri(linkText) Dim URL_WebRequest As System.Net.WebRequest Dim URL_WebResponse As System.Net.WebResponse Dim Response_Result As Boolean TryURL_WebRequest = System.Net.WebRequest.Create(URL_Object)
URL_WebResponse = URL_WebRequest.GetResponse
Response_Result =
True CatchResponse_Result =
False End TryURL_WebResponse =
NothingURL_WebRequest =
NothingURL_Object =
Nothing Return Response_Result End Function
reggiepangilinanX wrote:
"Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )"
what is the meaning of this
httpWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
httpWebRequest.GetResponse();