2

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?

1 Answer 1

2

(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/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, using file_get_contents('php://input') instead of $_POST did the trick!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.