2012-02-15 85 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