I've posted XML to a server via the command line curl and I've been completely successful. The only option I'm actually setting is the a header to set the content-type to application/xml.
When I turn around and try this in PHP I'm getting a 500 server error.
As far as curl options all I'm setting are as follows:
curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); curl_setopt($curl, CURLOPT_POSTFIELDS, $request); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
I've even gone so far as to copy and paste the XML output from the PHP application into the command line curl and it works just fine. I've tried various other curl options in different combinations with no luck.
If I had to guess there is some kind of encoding issue that is occurring but I've tried urlencoding the data and I actually get back a bad request instead of the 500.
I'm at a complete loss so if anyone has any ideas I'd love to hear them.
Try to modify the content-type option from:
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
It's worth noting that the cURL PHP has installed doesn't have to be the same version as the one you have installed on you server. Check to see what version you have installed on CLI (
$ curl --version) and then check PHP with something like
The problem was not PHP. I was not paying close attention to the error output from the server. Command line curl was failing at the same place every time due to a database constraint on a transaction id but was actually displaying the expected output causing me to think it was working correctly.
PHP, which was using the current hour, minute, second for the transaction id was getting past the point of failure in the command line and failing at a null value, which was actually a problem with my XML. The problem was the null value is an unhandled exception in the code on the remote server so the response back left me thinking something else had gone wrong.
Thanks for the help and sorry about the wild goose chase.