I am working on third party api and need to post data in curl with "xml http headers".I had tried it with many ways but api does not return any error or any response.It returns empty response.This is my code
$url = 'https://google.com'; // example url
$fields=array(
'apikey' =>'xxxxxxxxxxxxxxxxxx',
'totalItemAmount' => '70.00',
'totalPaymentAmount' =>'70.00',
'OrderNo' => '1234',
'PhoneNo' => '1823434423',
'addressCode' => 'S',
'lastName' => 'Johnson',
'firstName' =>'Thomas',
'addressLine1' => '345 D lake',
'city' =>'Chicago',
'stateCode' => 'IL',
'zipCode' =>'60579',
'countryCode' => 'US',
'itemQty' =>'2'
);
$fields_string = '';
//url-ify the data for the POST
foreach($fields as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array('Content-Type: application/xml', 'Accept: application/xml'),
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => $url,
CURLOPT_POST => count($fields),
CURLOPT_POSTFIELDS => http_build_query($fields)
));
//execute post
$result = curl_exec($ch);
print_r($result);
//close connection
curl_close($ch);