控制Roku框不起作用的脚本


Script to control Roku box not working

Roku 盒子可以通过一个简单的 RESTful 服务进行外部控制,该服务通过端口 8060 上的 http 协议访问,请参阅此处。我需要执行的命令是通过没有正文的 POST 发送的。它们提供了命令行 curl 示例,例如:

$ curl -d '' http://192.168.1.134:8060/keypress/home

我需要将其编写为PHP脚本,该脚本将执行一系列操作:按键/主页,启动/appid,按键/选择,按键/右键,按键/右键,按键/选择。

请参阅下面的内容,了解我想出的一个命令。 两个问题:

1)我的Roku没有对此做出回应,那么我做错了什么?
2) 一个接一个地发送多个 POST 请求的最佳方法是什么?

<?php
$ch = curl_init('http://192.168.1.134:8060/keypress/home');
$data = '';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
?>

按照您尝试这样做的方式,您的Web/PHP服务器应该能够直接访问您的Roku,而通常情况并非如此。服务器是否位于同一网络 192.168.1.* 上?

尝试 http://remoku.tv/看看您的 Roku 是否可以直接从浏览器中控制。

我找到了更好的方法,客户端使用javascript。

<script>
function post1() {
xhr = new XMLHttpRequest(); 
xhr.onload=function()
{
    alert(xhr.responseText);
}
xhr.open("POST", "http://192.168.1.134:8060/keypress/home");
xhr.send(); 
}
</script>
<body onload="post1()">