来自rtorrent的空xmlrpc响应

时间:2014-02-25 08:54:44

标签: php xml-rpc libtorrent

我想编写自己的rTorrent WebUI并使用xmlrpc完成我的第一步。但不知何故,它并没有真正起作用......

这是我为HTTP POST请求编写的函数:

function request($method, $args) {
    $data = xmlrpc_encode_request($method, $args);
    $ch = curl_init('http://#####/RPC2/');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = xmlrpc_decode(curl_exec($ch));
    curl_close($ch);
    return $response;
}

现在获取torrent列表......

$data['hash'] = request('download_list',null);
print_r($data);
Array
(
    [hash] => Array
        (
            [0] => 0CF0C7F75D18281AE7C65309F6B798CEB149BCB8
            [1] => 8CAA3ED5CB29999A6DA84739FDFF2D6B04489833
        )

)

...并请求每个torrent / hash的信息(reference以获取可能的方法)。

foreach ($data['hash'] as $index => $hash) {
    echo   "d.get_name:       "; print_r(request('d.get_name',       $hash));
    echo "\nd.get_base_path:  "; print_r(request('d.get_base_path',  $hash));
    echo "\nd.get_hash:       "; print_r(request('d.get_hash',       $hash));
    echo "\nd.is_active:      "; print_r(request('d.is_active',      $hash));
    echo "\nd.get_down_total: "; print_r(request('d.get_down_total', $hash));
    echo "\nd.get_up_total:   "; print_r(request('d.get_up_total',   $hash));
    echo "\nd.get_size_bytes: "; print_r(request('d.get_size_bytes', $hash));
}

应显示有关匹配哈希的种子的信息,但只有少数有效。

d.get_name:       [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
d.get_base_path:  /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
d.get_hash:       0CF0C7F75D18281AE7C65309F6B798CEB149BCB8
d.is_active:      
d.get_down_total: 
d.get_up_total:   
d.get_size_bytes: 

d.get_name:       [Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
d.get_base_path:  /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
d.get_hash:       8CAA3ED5CB29999A6DA84739FDFF2D6B04489833
d.is_active:      
d.get_down_total: 
d.get_up_total:   
d.get_size_bytes: 

Multicall可以在一个请求中获取所有内容。但同样在这里 - 不起作用。

print_r(request("d.multicall",array(
    "main",
    "d.get_name=",
    "d.get_base_path=",
    "d.get_up_total=",
    "d.get_size_bytes=",
    "d.get_down_total=",
    "d.get_completed_chunks=",
    "d.get_connection_current=",
    "d.get_connection_leech=",
    "d.get_connection_seed=",
    "d.get_creation_date="
)));
Array
(
    [0] => Array
        (
            [0] => [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
            [1] => /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
            [2] => 
            [3] => 
            [4] => 
            [5] => 
            [6] => seed
            [7] => 
            [8] => 
            [9] => 
        )

    [1] => Array
        (
            [0] => [Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
            [1] => /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 03 [h264-720p][C997AD9B].mkv
            [2] => 
            [3] => 
            [4] => 
            [5] => 
            [6] => seed
            [7] => 
            [8] => 
            [9] => 
        )
)

但是,全球请求工作正常。

print_r(request('view_list',null));
Array
(
    [0] => main
    [1] => default
    [2] => name
    [3] => active
    [4] => started
    [5] => stopped
    [6] => complete
    [7] => incomplete
    [8] => hashing
    [9] => seeding
    [10] => leeching
)
print_r(request('system.listMethods',null));
Array
(
    [0] => system.listMethods
    [1] => system.methodExist
    [2] => system.methodHelp
    [...]
    [959] => view_sort_new
    [960] => xmlrpc_dialect
    [961] => xmlrpc_size_limit
)

在请求函数中添加以下第一个torrent的xml-request的一些示例:

echo "request for \"$method\"\n".htmlentities($data)."\nresult: ";
request for "d.get_name"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_name</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: [Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
request for "d.get_base_path"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_base_path</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: /data/rtorrent/complete/[Anime-Koi] Tokyo Ravens - 01v2 [h264-720p][9E02D3C9].mkv
request for "d.get_down_total"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_down_total</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: 
request for "d.get_size_bytes"

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>d.get_size_bytes</methodName>
<params>
 <param>
  <value>
   <string>0CF0C7F75D18281AE7C65309F6B798CEB149BCB8</string>
  </value>
 </param>
</params>
</methodCall>

result: 

我做错了,只有一些请求返回任何有用的内容?

1 个答案:

答案 0 :(得分:3)

这是PHP-XMLRPC中的一个错误。

但是你可以替换你的行:

$response = xmlrpc_decode(curl_exec($ch));

使用:

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

这应该按预期工作。