【问题标题】:How to get an icecast header with dart如何用飞镖获得冰球头
【发布时间】:2014-06-08 19:40:36
【问题描述】:

我试图在服务器端使用 dart 获取 icecast 元数据。

我有一个带有检索元数据方法的对象。

为了获取元数据,我需要向 icecast 服务器发送一个带有特殊标头的 HttpRequest。 如果它是一个合适的 icecast 服务器,我应该得到一个带有键/值对的响应头 "icy-mettaint", "offset"

到目前为止我的飞镖代码。

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) {

    });

但现在我不知道如何实际发送请求,或者它是否是正确的方法。

任何帮助将不胜感激。

【问题讨论】:

    标签: dart httprequest icecast


    【解决方案1】:

    我认为您需要关闭请求才能真正发送它。

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

    您是否考虑过使用 http 包中的客户端? (就像这里显示的How to do POST in Dart command line HttpClient

    【讨论】:

    • 谢谢,有了你的建议,我可以让它工作。您实际上需要重新运行 request.close() 以发送请求并填充响应。
    【解决方案2】:

    这是一个工作示例(来自 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());
        });
    

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 2020-11-19
      相关资源
      最近更新 更多