Ich habe Code aus anderen Posts genommen, um die Apache App zu implementieren, um die Node App anzufordern. Die folgende Knoten-App "funktioniert", aber ich kann nicht auf Post-Parameter zugreifen, die nicht definiert sind.(apache, nodejs) Requesting Node App von PHP
//NODE
express = require('express');
bodyParser = require('body-parser');
app = express();
port = 3000;
app.use(bodyParser.json());
app.post('/get_php_data', function (req, res) {
// php array will be here in this variable
var data = req.param.data; // I've tried req.body.data;
var response = String(data)+String((7*data+3*data+1*data) % 3);
console.log(req); // This seems log req parameter in a loop
res.send(data);
});
app.listen(port);
PHP-Teil (POST nur Anforderung mit einem Parameter):
echo httpPost('localhost:3000/get_php_data', array('data' => 1));
function httpPost($url,$params)
{
$postData = http_build_query($params);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
Dieses Setup undefined zurück. Wie kann man mit Node auf POST-Parameter zugreifen?