I'm trying to use the Last.fm API for an application I'm creating, but am having some problems with validation.
If an API request gives an error it returns a code and message in the response XML like this:
<lfm status="failed">
<error code="6">No user with that name</error>
</lfm>
However, the request also returns an HTTP status of 400 (or in some cases 403) which DOMDocument considers an error and so then refuses to parse the XML.
Is there any way round this, so that I can retrieve the error code and message?
Thanks
Pete
I resolved the issue by using try & catch. If it can help someone
The Function:
Usage:
You can always get the response with some other function like
file_get_contents
and then parse the XML withDOMDocument::loadXML
Edit:
http://www.php.net/manual/en/domdocument.load.php#91384
A solution could be to separate your manipulations in two steps :
DOMDocument
.There is an example of how you can use curl on the
curl_exec
manual page ; adding a few useful options, you could use something like this, I suppose :And, for more options (there are a lot of them ^^ ), you can take a look to the manual page of
curl_setopt
.