I am trying to get a XML response from an external service as shown below. Using php Curl to post info and receiving the response and trying to display in the browser.
However I get the following error:
XML Parsing Error: syntax error Location: Line Number 1, Column 1:
<?xml version="1.0" encoding="utf-8"?>
^
can you help me whats the source of this and what does this error imply?
This is my code:
<?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);
?>