PHP CURL POST - xml响应错误

时间:2012-12-27 20:24:35

标签: php xml curl

我正在尝试从外部服务获取XML响应,如下所示。使用php Curl发布信息并接收响应并尝试在浏览器中显示。

但是我收到以下错误:

  

XML解析错误:语法错误位置:第1行,第1列:
  <?xml version="1.0" encoding="utf-8"?>
  ^

你能帮助我了解这个错误的来源吗?这个错误意味着什么?

这是我的代码:

<?php
header ("Content-type: text/xml");
//defining $vars here...not shonw for simplicity

$url = 'http://secure.leadexec.net/leadimport.asmx/LeadReceiver';
$myvars = '&VID=' . $lead_id . '&LID=' . '2' . '&AID=' . $lead_id . '&FirstName=' . $fname . '&LastName=' . $lname .
       '&Email=' . $email . '&MoveDate='. $move_date . '&Telephone=' . $phone . '&Address=' . $address . 
       '&Website=' . $website . '&Zip=' . $zipcode . '&ServicesNeeded=' . $services . '&RequestaQuote=' . $requestquote .
       '&NumberofEmployees=' . $no_of_employees . '&CompanyName=' . $company_name;

$ch = curl_init();
curl_setopt( $ch, CURLOPT_VERBOSE, 1); 
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_TIMEOUT, 40); 
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}

$oXML = new SimpleXMLElement($response);

foreach($oXML->entry as $oEntry){
    echo $oEntry->title . "\n";
}
if(curl_errno($ch))
print curl_error($ch);
else
print_r($response);
curl_close($ch);
?>

0 个答案:

没有答案