2012-02-15 86 views
0

我想從shoutcast中獲取源代碼。我讀了下面的代碼行:如何獲取shoutcast源代碼?

try { 
    URL game = new URL("http", "somewebsitename", 8013, "index.html"); 
    URLConnection connection = game.openConnection(); 
    BufferedReader in = new BufferedReader(new 
    InputStreamReader(connection.getInputStream())); 
    String inputLine; 
    while ((inputLine = in.readLine()) != null) { 
     System.out.println(inputLine); 
    } 
    in.close(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

而不是獲取源代碼,我使用Chrome,Firefox或Internet Explorer看到我得到這些線路:

ICY 404未找到資源 結冰,notice1 :
Shoutcast一樣分佈式網絡音頻服務器/ Linux的v1.9.8
冰冷-notice2:請求的資源沒有被發現

我確定文件存在於服務器上。

回答

0

我假設「從shoutcast獲得源代碼」,你的意思是你想從SHOUTcast管理面板頁面獲取HTML。

如果您想要管理面板,您需要在您的用戶代理字符串中有Mozilla。一旦你適當地設置你的用戶代理,你就沒有問題。

c.setRequestProperty("User-Agent", "Mozilla/Your-Applicaton-Name"); 

參見:Setting user agent of a java URLConnection