I'm trying to call an API using PHP xml-rpc. Here is the API I'm trying to retreive : https://rtorrent-docs.readthedocs.io/en/latest/cmd-ref.html#term-d-multicall2
So far I made the following :
<?php
$username "test";
$password = "test";
function do_call($username, $password, $request) {
$url = "https://$username:$password@example.com:32491/RPC2";
$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;
}
}
//$request = xmlrpc_encode_request("download_list", array()); //Give torrents hash
$request = xmlrpc_encode_request("d.multicall2", array("main", "d.name="));
$response = do_call($username, $password, $request);
var_dump($response);
Result :
string(310) " faultCode -501 faultString Unsupported target type found. "
Example call with xmlrpc :
rtxmlrpc --repr d.multicall2 '' tagged d.hash= d.name= d.custom=category
I don't understand why I'm getting this error
rTorrent version : 0.9.7/0.13.7
In issue 227 rakshasa says:
All commands are supposed to include a target as the first parameter, in this case an empty string.
So you need to call like this see the first empty string: $request = xmlrpc_encode_request("d.multicall2", array("", "main", "d.name="));