【发布时间】: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