1

im trying to get icecast metadata with dart on the server side of things.

i have an object with a method to retrive the metadata.

to get the metadata i need to send a HttpRequest to the icecast server with a special header. If its a propper icecast server, i should get a response header with the key/value pair "icy-metaint", "offset"

my dart code so far.

HttpClient client = new HttpClient();
    print(Uri.parse(this.src));
    client.getUrl(Uri.parse(this.src))
    .then((HttpClientRequest request) {
        request.headers.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36");
        request.headers.add("Icy-MetaData", "1");
    })
    .then((HttpClientResponse response) {

    });

but now i dont know how to actually send the request or if its even the right approach.

Any help would be greatly appreciated.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
arkhon
  • 765
  • 2
  • 11
  • 28

2 Answers2

2

I think you need to close the request to get it actually sent.

HttpClient client = new HttpClient();
    print(Uri.parse(this.src));
    client.getUrl(Uri.parse(this.src))
    .then((HttpClientRequest request) {
        request.headers.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36");
        request.headers.add("Icy-MetaData", "1");
        return request.close(); // <= close the request
    })
    .then((HttpClientResponse response) {
});

Have you considered using Client from the http package? (like shown here How to do POST in Dart command line HttpClient)

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Thanks, with your suggestion i could get it to work. You actually need to retrun the request.close() to send the request and populate the response. – arkhon Jun 08 '14 at 21:16
2

Here is a working example (with the suggestion from: Günter Zöchbauer)

HttpClient client = new HttpClient();
client.getUrl(Uri.parse(this.src))
    .then((HttpClientRequest request) {
        request.headers.add(HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36");
        request.headers.add("Icy-MetaData", "1");
        return request.close();
    })
    .then((HttpClientResponse response) {
        if(response.headers.value("icy-metaint") != null) {
            this.offset = int.parse(response.headers.value("icy-metaint"));
        }
        print(offset.toString());
    });
Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
arkhon
  • 765
  • 2
  • 11
  • 28