php-来自rtorrent的空xmlrpc响应
作者:互联网
我想编写自己的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;
}
现在获取种子列表…
$data['hash'] = request('download_list',null);
print_r($data);
Array
(
[hash] => Array
(
[0] => 0CF0C7F75D18281AE7C65309F6B798CEB149BCB8
[1] => 8CAA3ED5CB29999A6DA84739FDFF2D6B04489833
)
)
…并要求每个种子/哈希信息(可能的方法为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:
多通话可以在一个请求中获得所有信息.但是这里也一样-不起作用.
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:
我做错了什么,只有一些请求返回有用的东西?
解决方法:
这是PHP-XMLRPC中的错误.
但是,您可以替换行:
$response = xmlrpc_decode(curl_exec($ch));
带有:
$response = xmlrpc_decode(str_replace('i8>', 'i4>', curl_exec($ch)));
这应该按预期工作.
标签:xml-rpc,libtorrent,php 来源: https://codeday.me/bug/20191122/2056745.html