Solved: Check if URL exists

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Aftab

Thread Starter
Joined
Oct 15, 2003
Messages
72
I've got an app which streams images from a URL and saves them locally. I'm using the
System.Net.WebRequest and System.Net.WebResponse classes to achieve this. When the URL is valid it's fine, everything works OK, but when it's given an invalid URL, of a domain that doesn't exit, no exception is thrown and the request is redirected to openDNS. This leads to the stream writing out a small file which contains the contents of the openDNS response page. Clearly this is not the behaviour I'm after. If the URL is invalid I want an exception to be thrown. Even the statusDescription of the response says "OK". Does anyone know how I can get around this? BTW it's in C#.

Thanks
 

midders

Account Closed
Joined
Dec 31, 1969
Messages
645
Have a browse around MSDN C# function reference, I'm sure you'll find a function that will return the IP address of an URL or similar info that you can use to test the URL prior to your problem call.

Slainte

midders
 
Joined
Feb 17, 2008
Messages
490
IPAddress IP = Dns.GetHostByName(Server).AddressList[0]; //Resolves a domain name to an IP address.

I think this will throw an exception and should be able to supply an IP address or a url as the "Server" argument.
 

Aftab

Thread Starter
Joined
Oct 15, 2003
Messages
72
I will try your suggestion pvc_, it looks like what I need.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top