Java URL Connection Time Out

Posted by webren on Stack Overflow See other posts from Stack Overflow or by webren
Published on 2010-12-27T16:40:49Z Indexed on 2010/12/27 16:54 UTC
Read the original article Hit count: 214

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about java

Related posts about url