PHPスクリプトからnode.jsサーバーにJSONデータを送信したいと思います。PHPからJSONをcURL経由でnode.jsに送信
私の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の中で何をすべき?
あなたのデータはreq.bodyで利用できるようになります
app.all('/push', function(req, res) {
// what to do here?
});
チェックデータが 'はconsole.log(RES)を行うことによって掲示'と 'コンソールされている場合.log(req) ' – Jer
@ C0dekid.php req/resに関する私のデータはありません。 – mateuszji