我正在测试一个成功访问我的帐户的 XML API,并且我收到了响应,但响应似乎是一个纯文本字符串,没有标签或任何东西,甚至没有名称/对值。我需要将响应捕获为 XML,以便我可以使用 XML 标记来识别响应变量。
我使用表单 POST 将表单中的数据传递到 CURL 页面,该页面将 POST 解析为 XML 格式,然后使用 CURL 将其发送到 API。API 是基于 XML 的,我期望 XML 响应,但接收
帮助!
CURL 请求/响应页面
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<request>";
foreach ($_POST as $key => $val) {
$xml .= "<".$key.">". $val ."</".$key.">";
}
$xml .= "<username>user1234</username>";
$xml .= "<password>pass1234</password>";
$xml .= "</request>";
echo "<br/>" . $xml . "<br/><br/>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.beanstream.com/scripts/process_transaction.aspx');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
}
?>
带有标头的API 响应
HTTP/1.1 200 OK Cache-Control: private Content-Length: 724 Content-Type: application/xml; charset=utf-8 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Set-Cookie: ASP.NET_SessionId=1p4jp2uoz2de3f45iolold3j; path=/; HttpOnly Date: Wed, 16 Oct 2013 21:39:38 GMT 1100001211ApprovedQCE9HW5ETESTNT53.4810/16/2013 2:39:38 PM1W001Postal/ZIP matches, street address does not match.1VIPCC7