Reputation: 765
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.
Upvotes: 1
Views: 256
Reputation: 765
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());
});
Upvotes: 2
Reputation: 658107
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)
Upvotes: 2