Php xmlrcp 客户端获取 rtorrent 信息


Php xmlrcp client get rtorrent info

我需要创建简单的 php 脚本来获取我的 rtorrent 实例的一些信息......我尝试了很多代码,但我从不给出回应......

这是我的最后一次测试

ini_set('display_errors', 1);
error_reporting(E_ALL);
function do_call($host, $port, $request) {
    $url = "http://$host:$port";
    $header[] = "Content-type: text/xml";
    $header[] = "Content-length: ".strlen($request);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    $data = curl_exec($ch);
    if (curl_errno($ch)) {
        print curl_error($ch);
    } else {
        curl_close($ch);
        return $data;
    }
}
$host = '127.0.0.1';
$port = 10001;
$request = xmlrpc_encode_request("system.listMethods()", null);
$response = do_call($host, $port, $request);
var_dump($response);

你有简单的工作测试代码吗?

这是

PHP-XMLRPC中的一个错误。

但是,您可以更换您的行:

$data = curl_exec($ch);

跟:

$data = xmlrpc_decode(str_replace('i8>', 'i4>', curl_exec($ch)));

这应该按预期工作。