views:

21

answers:

1

Hi, I'm trying to read data from a webpage, and I have to do it using Java. When I try to do it in Eclipse using Java i'm getting time out error: java.net.ConnectException: Connection timed out: connect (Using HttpURLConnection):

URL yahoo = new URL("http://www.yahoo.com/"); 
URLConnection yc = yahoo.openConnection(); 
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null) 
    System.out.println(inputLine);
in.close();

In order to understand where is the problem I tried doing the same task using c# and VS2008, and it worked perfectly fine, no time out at all.

I'm doing this from work so there's a firewall but I don't have information about it.

What can be the reason for this?

Thanks! Daniel

A: 

I'm using this code: URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine;

            while ((inputLine = in.readLine()) != null) 
                System.out.println(inputLine);
            in.close();

found from here: http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

I'm doing this from work so there's a firewall but I don't have information about it.

Daniel
URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close();The full code, sorry about that
Daniel