I have an API which says all requests are made as POST requests with data in XML format, and it gives me a sample XML data:
<?xml version="1.0" ?>
<Request>
<SystemName>SomeSystemName</SystemName>
<Client>SomeClientID</Client>
<Method action="SomeAction">MethodParams</Method>
</Request>
Now I use curl to do it, like in this function:
function curl_post_xml($url, $xml, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $xml,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
And in $xml
I put that XML string from above. Am I doing it right? Because I heard that when using POST, the data must be in key-value format, but the API doesn't say anything about which variable should I assign XML string to.