Reputation: 214
I have a cURL response:
<html version="-//W3C//DTD XHTML 2.0//EN" xml:lang="en" xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/MarkUp/SCHEMA/xhtml2.xsd" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HEAD>
<TITLE>Request Error</TITLE>
</HEAD>
<BODY>
<DIV id="content">
<P class="heading1"><B>Error Status Code:</B> 'BadRequest'</P>
<P><B>Details: </B>Customer email address is not unique - [email protected]</P>
</DIV>
</BODY>
</html>
And when I convert it to an XML Object via SimpleXMLElement I cannot access the content inside the P tags. Is there a quick way to either get the header response (400) or even better the information sent by the cURL system.
I am getting back the result:
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLCERT, SPEKTRIX_CERT);
curl_setopt($ch, CURLOPT_SSLKEY, SPEKTRIX_KEY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'handleHeader');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'handleHeader');
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w'));
$requestHeaders = array();
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
$result = curl_exec($ch);
Thanks for any insights
Upvotes: 0
Views: 837
Reputation: 7389
How about this:
...prepare $ch...
$output = curl_exec($ch);
$info = curl_getinfo($ch);
echo $info['http_code']; // will output 400 for an invalid request
Upvotes: 2