0

我正在尝试从网页读取数据,我必须使用 Java 来完成。当我尝试在 Eclipse 中使用 Java 执行此操作时,出现超时错误:java.net.ConnectException:连接超时:连接(使用 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();

为了了解问题出在哪里,我尝试使用 c# 和 VS2008 执行相同的任务,它工作得非常好,根本没有超时。

我在工作中这样做,所以有防火墙,但我没有关于它的信息。

这可能是什么原因?

谢谢!丹尼尔

4

1 回答 1

0

我正在使用此代码: URL yahoo = new URL(" http://www.yahoo.com/ "); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); 字符串输入线;

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

从这里找到:http: //java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

我在工作中这样做,所以有防火墙,但我没有关于它的信息。

于 2010-05-25T06:37:22.783 回答