2

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.

Thanks!

6
  • Quick addition: the server response is a Null Exception Error, but again the data being sent should be identical... Commented Feb 14, 2012 at 20:09
  • 500 is usually a simple syntax issue turn error reporting on and you will probably find it. Commented Feb 14, 2012 at 20:10
  • Sorry, should have been more clear. The 500 is from the server curl is communicating with. Commented Feb 14, 2012 at 20:15
  • Check this thread stackoverflow.com/questions/8262355/… Commented Feb 14, 2012 at 20:21
  • Hmm ... I would think that if you're getting a 500 error back from the remote server there might be a problem on their end (as long as $request is valid XML, though I would expect a 400 Bad Request from that). I don't see any problems with the code you've posted. Is there any other code involved you might add to the question? Or perhaps the XML you're trying to POST? Commented Feb 14, 2012 at 20:22

3 Answers 3

1

Try to modify the content-type option from:

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));

to :

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
Sign up to request clarification or add additional context in comments.

2 Comments

My curl handle is in fact name $curl and the receiving server is very strict about only taking application/xml and not text/xml.
Did you specify the url you are posting to?
1

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 <?php phpinfo();.

1 Comment

Thanks for the help but the problem was actually completely unrelated. Just a case of mistaken expectations on my end.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.