Skip to content

Instantly share code, notes, and snippets.

@jnaskali
Created March 8, 2012 10:08
Show Gist options
  • Save jnaskali/2000102 to your computer and use it in GitHub Desktop.
Save jnaskali/2000102 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;
}
@jamminjames
Copy link

I'm getting an "Array to string conversion" error for line 9. I'm sure it's a good xml file though.

What can I do to debug this?

Thanks for any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment