I want to post XML data by using curl. I am using these code lines:
$data = '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
$data.= "<contacts>\r\n";
$data.= "<contact>\r\n";
$data.= "<firstName>$firstName</firstName>\r\n";
$data.= "<lastName>$lastName</lastName>\r\n";
$data.= "<email>$Email_Address</email>\r\n";
$data.= "<status>normal</status>\r\n";
$data.= "<contact>\r\n";
$data.= "</contacts>\r\n";
$url = "https://app.sandbox.icontact.com/icp/a/".$account_id."/c/".$client_folder_id."/contacts";
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS,$data);
$response = curl_exec($handle);
When I get response,It shows me this message :
<?xml version="1.0" encoding="UTF-8"?>
<response>
<errors>
<error>The XML that was passed in your request was malformed. Please provide valid XML.</error>
</errors>
</response>
What I need to change in XML input.
Thanks
Its usually a problem where you need to url encode the xml before you send it. try
$data = urlencode($data)This will give you output such as
%3C?xml version="1.0" encoding="UTF-8"?%3Eetc.