J
James
I don't know if I'm barking up the wrong tree or not, but here goes.
Basically I just want to validate that a URL exists when a user enters it
into our system. Essentially a send out a little request to see if the page
actually loads or if it doesn't exist at all.
I've been using the following code I lifted, but I'm not sure where to take
it from here, or if I have the entirely wrong namespace/concept.
Dim request As HttpWebRequest =
CType(WebRequest.Create("http://www.thissitewontexist.com"), HttpWebRequest)
' Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4
request.MaximumResponseHeadersLength = 4
' Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials
Dim responser As HttpWebResponse
Try
responser = CType(request.GetResponse(), HttpWebResponse)
Catch
' Gets here if it fails, but I'd prefer a cleaner solution
End Try
After this block, StatusCode = OK for sites that worked.
I'm completely lost on how to do this smoothly, any thoughts?
Thanks,
James
Basically I just want to validate that a URL exists when a user enters it
into our system. Essentially a send out a little request to see if the page
actually loads or if it doesn't exist at all.
I've been using the following code I lifted, but I'm not sure where to take
it from here, or if I have the entirely wrong namespace/concept.
Dim request As HttpWebRequest =
CType(WebRequest.Create("http://www.thissitewontexist.com"), HttpWebRequest)
' Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4
request.MaximumResponseHeadersLength = 4
' Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials
Dim responser As HttpWebResponse
Try
responser = CType(request.GetResponse(), HttpWebResponse)
Catch
' Gets here if it fails, but I'd prefer a cleaner solution
End Try
After this block, StatusCode = OK for sites that worked.
I'm completely lost on how to do this smoothly, any thoughts?
Thanks,
James