Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MrDavidChz/c8351907630f862db7613c39afcd14d3 to your computer and use it in GitHub Desktop.
Save MrDavidChz/c8351907630f862db7613c39afcd14d3 to your computer and use it in GitHub Desktop.
PHP: Send XML over POST with cURL and save response
function sendXmlOverPost($url, $xml) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// For xml, change the content-type.
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // ask for results to be returned
// Send to remote and return data to caller.
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment