【发布时间】:2016-03-24 12:22:38
【问题描述】:
我想将 JSON 数据从我的 PHP 脚本发送到 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 中我应该做什么?
app.all('/push', function(req, res) {
// what to do here?
});
【问题讨论】:
-
通过
console.log(res)和console.log(req)检查数据是否发布 -
@C0dekid.php req/res 上没有我的数据。