开发者

WebRequest using c# (VS2008) is perfectly working but not on Java (Ecplise)

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 pe开发者_高级运维rfectly 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜