Grab XML stats via CURL

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2112
    Anonymous
    Inactive

    Hi, I’m trying to grab and parse the XML stats page from my local Firefly server using PHP with Curl and from the following URL:

    http://XX.X.X.XX:3689/xml-rpc?method=stats

    I know this page is protected using Basic Authorization however, I’ve tried sending the default login details (no username, ‘mt-daapd’ as password) yet this fails to authenticate on the Firefly server and simply returns the defualt 401 failed page. If I try it through my Browser it works fine with the same login credentials.

    I’ve also tested grabbing a protected page (again, controlled by Basic Authorization) from my Router and this works without any problems which leads me to believe my issue is solely with Firefly.

    Here is the basic code used:

    $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, ":mt-daapd");
    $statsXML = curl_exec($cURL);
    curl_close($cURL);
    echo($statsXML);

    If anyone can help point me in the right direction I’d greatly appreciate it.

    I’m new to Firefly and I’m totally loving it, fantastic product. Setting it up was a breeze (running on NSLU2) and runs like a dream with my SoundBridge M1001.

    – Mike

    #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

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.