473,507 Members | 9,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate an url

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

Nov 18 '05 #1
4 1736
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" <no@sorry.nl> 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?


Nov 18 '05 #2

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


Nov 18 '05 #3
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


Nov 18 '05 #4
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

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4562
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
5
2518
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
11
11732
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
2632
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
2580
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
2080
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.