我正在使用 cURL 将 HTML 表单的内容提交给第 3 方服务,它会向我返回一个 XML 响应。但无论我在做什么,我似乎都无法解析那个 XML 响应来自定义结果的显示。
以下是处理表单的代码(注意一些 ID 号码已被审查):
<?php
$FirstName = $_POST['FirstName'] ;
$LastName = $_POST['LastName'] ;
$Zip = $_POST['Zip'] ;
$EmailAddress = $_POST['EmailAddress'] ;
$PrimaryPhoneNumber = $_POST['PrimaryPhoneNumber'] ;
$DateofBirth = $_POST['DateofBirth'] ;
$myvars = '&VID=' . '****' . '&LID=' . '****' . '&AID=' . '****' . '&FirstName=' . $FirstName . '&LastName=' . $LastName .
'&EmailAddress=' . $EmailAddress . '&PrimaryPhoneNumber=' . $PrimaryPhoneNumber . '&Zip=' . $Zip . '&DateofBirth=' . $DateofBirth;
if ($FirstName!='' && $LastName!='' && $Zip!='' && $EmailAddress!='' && $PrimaryPhoneNumber!='' && $DateofBirth!='') {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://secure.leadexec.net/leadimport.asmx/LeadReceiver');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $myvars);
curl_exec ($c);
curl_close ($c);
} else {
echo '<p>Please make sure you have filled out the form completely</p>';
}
?>
这是我得到的响应的原始输出:
<?xml version="1.0" encoding="utf-8"?>
<PostResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.leadproweb.com/">
<isValidPost>false</isValidPost>
<ResponseType>Duplicate_Lead</ResponseType>
<ResponseDetails>Duplicate Lead, Last Received On: 9/27/2013 2:17:26 PM</ResponseDetails>
<LeadIdentifier>20889333</LeadIdentifier>
<VendorAccountAssigned>0</VendorAccountAssigned>
<PendingQCReview>false</PendingQCReview>
<Price>0</Price>
<RedirectURL />
</PostResponse>
当我尝试使用SimpleXmlElement或simplexml_load_string()之类的方法来解析 XML 时,它们似乎被忽略了,除非我删除curl_exec($c)行,否则我无法摆脱原始 XML 输出。
有什么我做错了吗?