Reputation: 1804
I wonder is it possible to write a console application that will surf to a web page without opening a browser? I want to check if a web page is alive (and check for an HTML string in it), but I don't want to open a web browser every time for this since I have a great number of web pages to check. What is the best way to go about this? I have some knowledge in java but not so much in networking with java.
any help or direction will be greatly appreciated.
Upvotes: 0
Views: 522
Reputation: 2376
You want java.net.URL.getConnection():
InputStream is = null;
try{
URL page = new URL("http://example.com/");
URLConnection connection = page.openConnection();
is = connection.getInputStream();
}
catch(MalformedURLException e)
{
// ....
}
catch(IOException e)
{
// Couldn't connect to website
}
// do something with input stream
Upvotes: 3
Reputation: 11
You might give this short tutorial a try: http://download.oracle.com/javase/tutorial/networking/urls/readingURL.html
Also you will find more code samples here: http://www.exampledepot.com/egs/java.net/pkg.html
Upvotes: 1