Results 1 to 2 of 2

Thread: SimpleXML - Problems with external file.

  1. #1
    Join Date
    Mar 2010
    Location
    England
    Posts
    1,144

    SimpleXML - Problems with external file.

    Does anyone know why this doesn't work?, I am using Last.fm API, so obviously, I am limited, but this shouldn't happen.

    I have 2 paths:
    1. http://ws.audioscrobbler.com/2.0/?me...ser=ChrisG4620
    2. http://ws.audioscrobbler.com/2.0/?me...er=ChrissG4620

    URL 1, has a correct username, and URL 2, has an incorrect username, so it would show an error.

    So i try running it through SimpleXML in PHP, if i parse url 1. It works fine. If i parse url 2, i get this error:

    Warning: SimpleXMLElement::__construct(http://ws.audioscrobbler.com/2.0/?me...er=ChrissG4620) [simplexmlelement.--construct]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\EasyPHP5.2.10\www\last.fm\includes\last_fm\test.php on line 3

    Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: I/O warning : failed to load external entity "http://ws.audioscrobbler.com/2.0/?method=user.getInfo&api_key=b25b959554ed76058ac220b7b2e0a026&user=ChrissG4620" in C:\EasyPHP5.2.10\www\last.fm\includes\last_fm\test.php on line 3

    Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\EasyPHP5.2.10\www\last.fm\includes\last_fm\test.php:3 Stack trace: #0 C:\EasyPHP5.2.10\www\last.fm\includes\last_fm\test.php(3): SimpleXMLElement->__construct('http://ws.audio...', 0, true) #1 {main} thrown in C:\EasyPHP5.2.10\www\last.fm\includes\last_fm\test.php on line 3
    --
    This is the PHP (with the wrong username)
    PHP Code:
    $result = new SimpleXMLElement'http://ws.audioscrobbler.com/2.0/?method=user.getInfo&api_key=cf6d5284dbbc825d5472c077c30b22ae&user=ChrissG4620'nullTRUE );

    print_r($result); 
    ---
    Anyone got any ideas why?, If you send an incorrect username, it shows an error in XML form, so how come the SimpleXML doesn't treat it like a normal request?

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    Was actually curious myself, so had a look at the headers. A 400 status code is being returned by the server (as mentioned in the error message). Problem solved.
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Similar Threads

  1. External sound file will not load
    By motionographer in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 26 Aug 2009, 09:35 AM
  2. Access external CSS file from PHP file?
    By web88js in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 08 Dec 2007, 07:52 AM
  3. Problems hyperlinking to certain file types
    By a_south in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 09 Jul 2007, 06:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •