用于VLC播放器的HTTP post命令

时间:2014-01-05 00:46:38

标签: qt http qml vlc

我正在尝试编写一个简单的移动应用程序来控制一些基本的VLC功能。我对此非常陌生,只是试图绕着整个事情包围我,但我一直在阅读并找到一些代码:

这是qml代码,我对我理解的部分进行了基本的更改:

Component.onCompleted: {
    var http = new XMLHttpRequest()
    var url = "http://" + ip + ":" + port;
    var params = "num=22&num2=333";
    http.open("POST", url, true);

    // Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");

    http.onreadystatechange = function() { // Call a function when the state changes.
        if (http.readyState == 4) {
            if (http.status == 200) {
                console.log("ok")
            } else {
                console.log("error: " + http.status)
            }
        }
    }
    http.send(params);
}

还找到了一些java代码:

webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
                string credentials = String.Format("{0}:{1}", username, password);
                byte[] bytes = Encoding.UTF8.GetBytes(credentials);
                string base64 = Convert.ToBase64String(bytes);
                string authorization = String.Concat("Basic ", base64);
                webClient.Headers["Authorization"] = authorization;
                string url = "http://" + ip + ":" + port + "/requests/status.xml";
                var uri = new Uri(url);
                webClient.DownloadStringAsync(uri);

我目前因QML丢失的部分是我不知道如何将凭据传递给登录,因为VLC需要密码。

是否有人能够帮助我如何更改qml代码以连接到http客户端,然后能够传递如下命令:

http://localhost:8080/requests/status.xml?command=pl_play

谢谢:)

1 个答案:

答案 0 :(得分:1)

不是那么精通QML,所以我只能提供伪代码。最简单的HTTP身份验证形式是通过包含字符串Authorization的{​​{1}}标头,后跟在base64中用冒号Basic分隔的空格和用户名和密码。

假设:返回传递数据的b64表示,则应执行以下操作:

base64()