473,666 Members | 2,449 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 1742
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.Cre ate(url);
// Sends the HttpWebRequest and waits for a response.
HttpWebResponse httpWebResponse =
(HttpWebRespons e)httpWebReques t.GetResponse() ;
if (httpWebRespons e.StatusCode == HttpStatusCode. OK)
Console.WriteLi ne("\r\nRespons e Status Code is OK and
StatusDescripti on is: {0}",
httpWebResponse .StatusDescript ion);
// Releases the resources of the response.
httpWebResponse .Close();

}
catch(WebExcept ion e)
{
Console.WriteLi ne("\r\nWebExce ption Raised. The following
error occured : {0}",e.Status) ;
}
catch(Exception e)
{
Console.WriteLi ne("\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 myHttpWebReques t =
(HttpWebRequest )WebRequest.Cre ate(url);
// Sends the HttpWebRequest and waits for a response.
HttpWebResponse myHttpWebRespon se =
(HttpWebRespons e)myHttpWebRequ est.GetResponse ();
if (myHttpWebRespo nse.StatusCode == HttpStatusCode. OK)
Console.WriteLi ne("\r\nRespons e Status Code is OK and
StatusDescripti on is: {0}",

myHttpWebRespon se.StatusDescri ption);
// Releases the resources of the response.
myHttpWebRespon se.Close();

}
catch(WebExcept ion e)
{
Console.WriteLi ne("\r\nWebExce ption Raised. The following
error occured : {0}",e.Status) ;
}
catch(Exception e)
{
Console.WriteLi ne("\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
4575
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) from Microfost MSDN Library for my project "validateXML". When I did "Build" on my project, I got the following fatal error C1010: c:\Documents and Settings\SHC\My Documents\Visual Studio Projects\valoidateDOM\valoidateDOM.cpp(273): fatal error...
5
2524
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 invoked. I am probably wrong about that. If I am suppose to use this function, the edits seemed to be invoked even when you have pressed the cancel and the "CausesValidation" is set to false. Is there a way to get around this (might just be an...
11
11754
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's the Page.IsValid method. Is there something similar in winforms, or do I still have to write an...
0
2642
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 XML document? I was hoping to use the XmlDocument.Validate(ValidationEventHandler, XmlNode) method for that - doesn't seem to work...
4
2590
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 figured since all the panel data is still being sent through the postbacks, instead of using Sessions, or HttpContext, I could just take the values from the textboxes. This all works fine, except for security. I realized that I could inject...
24
2098
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 automate and clean up parameter validation code. It's almost ready to go into open beta. But one last little glitch is holding me up, and that would be the name of the factory class that serves as the entry point into the library: Validate.
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6189
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.