POST xml to php with apache2
- by Berry
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?