【问题标题】:Shutdown Kodi with api (blackberry qml)使用 api (blackberry qml) 关闭 Kodi
【发布时间】:2021-01-25 05:50:48
【问题描述】:

您好,我尝试使用移动应用程序 (blackberry qml) 关闭 Kodi (raspberry pi)。 但我不知道。

我使用了这段代码:(在浏览器中)

"http://[myip]:[myport]/jsonrpc?request={"jsonrpc":"2.0","method":"System.Suspend","id":1}"

我使用了这段代码:(在应用程序中)

function sendRequest() {
    var xhr = new XMLHttpRequest();

    var url = "http://[myip]:[myport]/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\": \"System.Suspend\",\"id\":1}"

    xhr.onreadystatechange = function() {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {

                console.log(xhr.responseText);
                textArea.text = xhr.responseText;
            }
        }
    };
    xhr.open("GET", url, true); // with "POST" I got the same problem.
    xhr.send();
}

我得到: {"error":{"code":-32700,"message":"解析错误。"},"id":null,"jsonrpc":"2.0"}

从网络浏览器远程工作正常 (http://[myip]:[myport]) 谢谢你的回答。

********** 更新:21.10.2020 **********

我正在进行中。但我不知道下一步该做什么。 我找到了一些信息,为什么我有错误。 我不知道如何在我的代码中实现。

你能帮帮我吗? 非常感谢。

https://github.com/xbmc/xbmc/pull/12281

https://forum.kodi.tv/showthread.php?tid=324598&highlight=json

这是怎么做的。但我看不懂。

https://retifrav.github.io/blog/2018/09/01/kodi-remote-control-app/

这是我的功能(在 Kodi 17.6 上它可以工作,但在 Kodi 18 上不工作)

function sendRequest() {

    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
                text.text = xhr.responseText
            }
        }
    };

    var url = 'http://<IP:PORT>/jsonrpc?request={"jsonrpc": "2.0", "id": 1, "method": "System.Shutdown"}'
    xhr.open("GET", url, true) // when I write "POST" - nothing happens
    xhr.send()
}

【问题讨论】:

  • HTTP GET 请求应该是幂等方法,并且相同的请求应该返回相同的响应。因此,您可能会发送不同的请求,而错误代码可能是对此的间接确认。我建议您使用一些工具(我通常使用 Postman)来比较来自 2 个目标的请求。
  • 您的 json 文件中 1 之前有一个不必要的斜线 /
  • 罗杰·勒布朗 - 谢谢。我修好了。但还是同样的问题。

标签: api http qml blackberry kodi


【解决方案1】:

在将 json 用于 open 方法之前,您应该对 url 中的 json 进行 URL 编码。使用 encodeURIComponent() 来做到这一点。您的浏览器正在更改:

{"jsonrpc":"2.0","method": "System.Suspend","id":1}"

收件人:

%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%20%22System.Suspend%22%2C%22id%22%3A1%7D%22

但你的代码不是。

【讨论】:

  • 谢谢,我发现我不必这样做。在 Kodi 17.6 上测试
猜你喜欢
  • 1970-01-01
  • 2016-03-23
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多