tags:

views:

364

answers:

1

Consider a PHP script that outputs all POST data, as follows:

<?php var_dump($_POST); ?>

The script is located at http://example.com/foo.php.

Now, I want to post XML data to it (without using key/value pairs) using command line curl. I have tried many variations of the following:

curl -H "Content-type: text/xml; charset=utf-8" --data-urlencode "<foo><bar>bazinga</foo></bar>" http://example.com/foo.php

Yet none of them seem to actually post anything — according to the PHP script, $_POST is just an empty array.

What am I doing wrong here?

+2  A: 

(Disclaimer: My familiarity with PHP is passing and ancient.)

I believe $_POST only works if PHP can parse the input as the normal key/value pairs. You need to access the raw POST data directly. This might be useful:

http://www.codediesel.com/php/reading-raw-post-data-in-php/

Nicholas Knight
Thanks, using `file_get_contents('php://input')` instead of `$_POST` did the trick!
Mathias Bynens