简体   繁体   中英

POST xml to php with apache2

I'm working on an application that receives XML data via POST, processes it with a PHP script, and returns an XML response.

I'm getting the XML with this PHP code:

$requestStr = file_get_contents('php://input');
$requests = simplexml_load_string($requestStr);

which works fine on the Linux-based product hardware using nginx as the server.

However, for testing I'd like to be able to run it on my MacBook Pro, so I can avoid the "build image, install on product, reboot product, wait, test change" loop while I do targeted development on this XML processor.

I enabled "web sharing" which starts up Apache, added a rewrite rule to point a convenient URI at my development source directory and used curl to send a request to my PHP script thus:

curl -H "Content-Type:text/xml" -d @request.xml http://localhost/test/path/testscript

"testscript" is handled by the PHP script fine, but when it goes to read "php:://input" I get nothing -- the empty string.

Anyone have a clue why this would work under Linux with nginx and not under MacOS with Apache?

I've googled and searched stackoverlow.com to no avail. Thanks for any answers.

UPDATE: I've discovered that at least in this configuration, reading from php://stdin will work fine, while php://input will not. Who knew?

Not familiar with nginx or MacOS, but with FreeBSD/Apache there is another way you might try:

$xml_in = $GLOBALS["HTTP_RAW_POST_DATA"];

You must also add this to the .htaccess:

php_value always_populate_raw_post_data 1

HTH, Kevin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM