0

我有一个 cURL 响应:

<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 - xxxxxxxxx@xxxxxx.com</P>
</DIV>
</BODY>
</html>

当我通过 SimpleXMLElement 将其转换为 XML 对象时,我无法访问 P 标签内的内容。有没有一种快速的方法来获取标头响应(400),或者更好地获取 cURL 系统发送的信息。

我得到了结果:

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);

感谢您的任何见解

4

1 回答 1

2

这个怎么样:

...prepare $ch...
$output = curl_exec($ch);
$info = curl_getinfo($ch);
echo $info['http_code']; // will output 400 for an invalid request
于 2012-04-26T10:18:45.750 回答