Java URL Connection Time Out
- by webren
Hello, I am attempting to connect to a website where I'd like to extract its HTML contents. My application will never connect to the site - only time out.
Here is my code:
URL url = new URL("www.website.com");
URLConnection connection = url.openConnection();
connection.setConnectTimeout(2000);
connection.setReadTimeOut(2000);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream());
String line;
while ((line = reader.readLine()) != null) {
// do stuff with line
}
reader.close();
Any ideas would be greatly appreciated. Thanks!