无法获取在线ShoutCast流的标题

问题描述 投票:0回答:1

我已经工作了24小时,以查找此在线流的问题:http://str45.streamakaci.com:8014您可以尝试一下,它可以正常工作,但是当我尝试使用Java从中获取标头时我明白了:

Sending 'GET' request to URL : http://str45.streamakaci.com:8014
Response Code : -1
Response Message : {Content-type=[unknown/unknown]}

当我使用SMSSniffer来查看返回的HTTP标头发生了什么是正确的并且得到此信息时

GET / HTTP/1.1
Content-Type: text/html; charset=UTF-8
Icy-MetaData: 1
Accept-Encoding: gzip
Content-Encoding: gzip, deflate
Cache-Control: no-cache
User-Agent: Java/1.8.0_131
Host: str45.streamakaci.com:8014
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive


ICY 200 OK
icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
icy-notice2:SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>
icy-name:Radio Flemme MP3
icy-genre:Various
icy-url:http://www.radioflemme.com
content-type:audio/mpeg
icy-pub:0
icy-metaint:32768
icy-br:128 

标题下方有一些长文本。

这里是获取HTTP标头的Java代码,该标头可以与其他ShoutCast流配合使用,但不能与之兼容。

 private static void sendGet() throws Exception {

            String url = "http://str45.streamakaci.com:8014";

            HttpURLConnection httpClient =
                    (HttpURLConnection) new URL(url).openConnection();

            // optional default is GET
             httpClient.setRequestMethod("GET");

            //add request header
             httpClient.setRequestProperty("Content-Type", "text/html; charset=UTF-8");

            httpClient.setRequestProperty("Icy-MetaData", "1");
            httpClient.setRequestProperty("Accept-Encoding", "gzip");
            httpClient.setRequestProperty("Content-Encoding", "gzip, deflate");
            httpClient.setRequestProperty("Cache-Control", "no-cache");
           int responseCode = httpClient.getResponseCode();
            System.out.println("\nSending 'GET' request to URL : " + url);
           System.out.println("Response Code : " + responseCode);

            String name = httpClient.getHeaderField("icy-metaint");
           // System.out.println("Response name : " + name);
            System.out.println("Response Message : " +  httpClient.getHeaderFields());

        }

[任何人都可以帮助我解决这个问题。问候

java http header httpurlconnection shoutcast
1个回答
0
投票

URL http://str45.streamakaci.com:8014确实正确返回了标题,这是一个使用lynx检查终端中标题的命令:

lynx -mime_header http://str45.streamakaci.com:8014
HTTP/1.0 200 OK
content-type:text/html

<HTML><HEAD><meta http-equiv="Content-Language" content="en-us"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><meta http-equiv="Pragma" content="no-cache">.... HTML follows

尚不是100%清楚您要寻找的内容,以防万一我会提到http://str45.streamakaci.com:8014URL是Shoutcast“状态”页面的地址,而不是音频流。如果要音频流,URL将为:http://str45.streamakaci.com:8014/;stream最后的“ stream”并不重要,可以是任何字符串,甚至可以是http://str45.streamakaci.com:8014/;会很好的工作。因此,让我们检查流头:

lynx -mime_header "http://str45.streamakaci.com:8014/;stream"
ICY 200 OK
icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
icy-notice2:SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>
icy-name:Radio Flemme MP3
icy-genre:Various
icy-url:http://www.radioflemme.com
content-type:audio/mpeg
icy-pub:0
icy-br:128

这不是特定于Java的,我无法告诉您代码,但是可以确认此Shoutcast是否以正确的方式返回标头。

© www.soinside.com 2019 - 2024. All rights reserved.