0

I want to get the source code from a shoutcast. I read the lines with the code below:

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();
}

Instead of getting the source code which I see with Chrome, Firefox or Internet Explorer I get these lines:

ICY 404 Resource Not Found icy-notice1:
SHOUTcast Distributed Network Audio Server/Linux v1.9.8
icy-notice2:The resource requested was not found

I made sure the the file exists on the server.

Nando
  • 358
  • 3
  • 13

1 Answers1

0

I assume by "get the source code from a shoutcast" you mean you want to get the HTML from a SHOUTcast Admin Panel page.

If you want the admin panel, you need to have Mozilla somewhere in your User-Agent string. Once you set your User-Agent appropriately, you'll have no problem.

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

See also: Setting user agent of a java URLConnection

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530