Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > validate an url

Reply
Thread Tools

validate an url

 
 
Guoqi Zheng
Guest
Posts: n/a
 
      10-08-2004
How can I validate an URL in real time, connect to that URL directly and see
it response with ok status.

I think it might need to use webclient, or webrequest + webresponse, but I
have not found out how to do it.

Any help?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com



 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      10-09-2004
You can use either WebClient or WebRequest. I have an article using
both classes that does more than you need, but should give you more
than enough code to get started:

http://odetocode.com/Articles/162.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 9 Oct 2004 00:00:07 +0200, "Guoqi Zheng" <(E-Mail Removed)> wrote:

>How can I validate an URL in real time, connect to that URL directly and see
>it response with ok status.
>
>I think it might need to use webclient, or webrequest + webresponse, but I
>have not found out how to do it.
>
>Any help?


 
Reply With Quote
 
 
 
 
jongalloway
Guest
Posts: n/a
 
      10-09-2004

Guoqi Zheng wrote:
> How can I validate an URL in real time, connect to that URL directly

and see
> it response with ok status.
>
> I think it might need to use webclient, or webrequest + webresponse,

but I
> have not found out how to do it.
>
> Any help?
>
> --
> Kind regards
>
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com


 
Reply With Quote
 
jongalloway
Guest
Posts: n/a
 
      10-09-2004
Guoqi -

Check for HttpWebResponse.StatusCode == HttpStatusCode.OK.

Sample function from MSDN
(http://msdn.microsoft.com/library/de...scodetopic.asp)

public static void GetPage(String url)
{
try
{
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for a response.
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode == HttpStatusCode.OK)
Console.WriteLine("\r\nResponse Status Code is OK and
StatusDescription is: {0}",
httpWebResponse.StatusDescription);
// Releases the resources of the response.
httpWebResponse.Close();

}
catch(WebException e)
{
Console.WriteLine("\r\nWebException Raised. The following
error occured : {0}",e.Status);
}
catch(Exception e)
{
Console.WriteLine("\nThe following Exception was raised :
{0}",e.Message);
}
}

- Jon
http://weblogs.asp.net/jgalloway

Guoqi Zheng wrote:
> How can I validate an URL in real time, connect to that URL directly

and see
> it response with ok status.
>
> I think it might need to use webclient, or webrequest + webresponse,

but I
> have not found out how to do it.
>
> Any help?
>
> --
> Kind regards
>
> Guoqi Zheng
> guoqi AT meetholland dot com
> Http://www.meetholland.com


 
Reply With Quote
 
jongalloway
Guest
Posts: n/a
 
      10-10-2004
Guoqi -

You need to check the HttpWebRequest.Status property. Sample code from
MSDN:

http://msdn.microsoft.com/library/de...scodetopic.asp

public static void GetPage(String url)
{
try
{
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for a response.
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
Console.WriteLine("\r\nResponse Status Code is OK and
StatusDescription is: {0}",

myHttpWebResponse.StatusDescription);
// Releases the resources of the response.
myHttpWebResponse.Close();

}
catch(WebException e)
{
Console.WriteLine("\r\nWebException Raised. The following
error occured : {0}",e.Status);
}
catch(Exception e)
{
Console.WriteLine("\nThe following Exception was raised :
{0}",e.Message);
}
}

- Jon
http://weblogs.asp.net/jgalloway

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regEx to validate a web url franz ASP .Net 2 09-14-2005 08:55 PM
How to validate a URL ALI-R ASP .Net 5 11-12-2004 10:42 PM
URL - substitution of a correct URL by a GUID like URL in favorites. Just D. ASP .Net Mobile 0 08-11-2004 04:26 PM
redirect URL's, return URL's, and URL Parameters Jon paugh ASP .Net 1 07-10-2004 05:29 AM
Solution for: "Unable to validate that the file <name> matches the URL <url>" Doug ASP .Net 0 07-06-2003 02:40 PM



Advertisments