开发者

Posting XML via curl (command-line) without using key/value pairs

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜