使用c#(VS2008)的WebRequest完全正常工作,但不适用于Java(Eclipse)

时间:2010-05-25 06:23:58

标签: java timeout httpurlconnection

我正在尝试从网页上读取数据,而我必须使用Java来完成。 当我尝试使用Java在Eclipse中执行此操作时,我遇到了超时错误: 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完成相同的任务,它完全正常,没有时间。

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

这可能是什么原因?

谢谢! 丹尼尔

1 个答案:

答案 0 :(得分:0)

我正在使用此代码:                 网址yahoo =新网址(“http://www.yahoo.com/”);                 URLConnection yc = yahoo.openConnection();                 BufferedReader in = new BufferedReader(                                         新的InputStreamReader(                                         yc.getInputStream()));                 String inputLine;

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

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

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