2010-05-25 34 views
0

我試圖從網頁讀取數據,我必須使用Java來完成。 當我嘗試使用Java我得到超時錯誤做在Eclipse: java.net.ConnectException:連接超時:連接 (使用HttpURLConnection類):使用c#(VS2008)的WebRequest是完全正常工作,但不是在Java(Ecplise)

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做同樣的任務,並且它工作得很好,沒有時間。

我正在做這個工作,所以有一個防火牆,但我沒有關於它的信息。

這可能是什麼原因?

謝謝! Daniel

+0

1. Java不是首字母縮寫詞。 2.您需要張貼一些源代碼,並提供其他相關信息(任何防火牆等)。 – 2010-05-25 06:28:31

回答

0

我使用此代碼: 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(); 

從這裏找到:http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

我從工作做這所以有一個防火牆,但我沒有關於它的信息。

+0

URL yahoo = new URL(「http://www.yahoo.com/」); \t \t URLConnection yc = yahoo.openConnection(); \t \t的BufferedReader在新=的BufferedReader( \t \t新的InputStreamReader( \t \t yc.getInputStream())); \t \t String inputLine; \t \t而((inputLine = in.readLine())!= NULL) \t \t的System.out.println(inputLine); \t \t in.close(); 完整的代碼,很抱歉 – Daniel 2010-05-25 06:38:11

相關問題