-
-
Save MrDavidChz/c8351907630f862db7613c39afcd14d3 to your computer and use it in GitHub Desktop.
PHP: Send XML over POST with cURL and save response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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