View Single Post
Old Nov 11th, 2007, 10:34 PM   #4
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Re: Network Programming Help.

HttpURLConnection has a method called getResponseCode() and returns 200 if its a valid page. Once you parse the links from the HTML source, you can put them into a list and iterate through the list of urls to see if they are valid. Here is a method that you could use. My Java skills are a bit rusty so bare with me.
public bool isValidUrl(String urlStr)
{
	try
	{
		java.net.URL url = new java.net.URL(urlStr);
		java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection)url.openConnection();
		httpConn.connect();
		if(httpConn.getResponseCode() != 200)
			return false;
		else
			return true; //it does return 200 and is a valid link
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}

}
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote