Reply To: Grab XML stats via CURL

#15769
Anonymous
Inactive

After racking my brains for a short while and nothing seeming to work, I gave up and worked on something else. Then in the middle of the night I suddenly thought of something that might be a possibility, and it worked! Funny how that happens – I think they call it a “Eureka!” moment.

For those who might be interested in the solution; I discovered that by simply suppling a dummy username (as Firefly doesn’t seem to worry about what username is supplied as long as the password is correct) I was able to successfully log in and retrieve the necessary data. I guess CURL wasn’t happy with sending a blank value for the username field, or perhaps it was sending the password first (or on it’s own) because a username had not been supplied.

So to iterate, my working code now looks like the following:

$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "http://XX.X.X.XX:3689/xml-rpc?method=stats");
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_USERPWD, "dummyName:mt-daapd");
$statsXML = curl_exec($cURL);
curl_close($cURL);
echo($statsXML);

Hope this comes in handy for anyone else who might stumble upon this issue.

– Mike