Я хочу отправить данные JSON из моего PHP-скрипта на node.js-сервер.Отправить JSON от PHP до node.js через cURL
Мой PHP файл выглядит:
$data = array("name" => "Lorerm", "age" => "18");
$data_string = json_encode($data);
$ch = curl_init('http://localhost:3000/push');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_exec($ch);
Что я должен делать в Node.js?
app.all('/push', function(req, res) {
// what to do here?
});
Проверьте, если данные размещены делая 'console.log (Рез)' и 'консоли .log (req) ' – Jer
@ C0dekid.php отсутствуют мои данные по req/res. – mateuszji