I am trying to run a simple web application through the ReactPHP web server, but I cannot figure out where to get the POST data from the HTML form. The server is defined as:
include 'vendor/autoload.php';
register_shutdown_function(function() {
echo implode(PHP_EOL, error_get_last()), PHP_EOL;
});
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', function(React\Http\Request $request, React\Http\Response $response) {
print_r($request);
$response->writeHead(200, array('Content-type' => 'text/html'));
$response->end('<form method="POST"><input type="text" name="text"><input type="submit" name="submit" value="Submit"></form>');
});
$socket->listen(9000);
$loop->run();
When I submit a line using an HTML form, the object $requestwhen printed on the console looks like this:
React\Http\Request Object
(
[readable:React\Http\Request:private] => 1
[method:React\Http\Request:private] => POST
[path:React\Http\Request:private] => /
[query:React\Http\Request:private] => Array
(
)
[httpVersion:React\Http\Request:private] => 1.1
[headers:React\Http\Request:private] => Array
(
[User-Agent] => Opera/9.80 (X11; Linux i686) Presto/2.12.388 Version/12.16
[Host] => localhost:9000
[Accept] => text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, *
Here I can not find my data anywhere. I thought it should be in the property query, but it is empty.
When I make GET requests, instead, the data passed to querystring can be found inside the queryobject property $request.
So where can I find the data transmitted with POST requests?
source
share