如何在node.js中提取POST参数?

时间:2013-06-04 04:44:18

标签: node.js drupal-7

我试图将数据从Drupal页面发送到节点

Drupal代码

function sample_submit($form, &$form_state) { //Function to connect with node and save into Mongo using node
  $jsonData = check_plain($form_state['values']['jsonData']);
  $request_url = "http://10.20.5.112:3000/save";
  $options = array(
                'method' => 'POST',
                'data' => $jsonData,
                'timeout' => 15,
                'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
        );
    $result = drupal_http_request($request_url, $options);
}

Node.js的

app.post('/save', function(req, res){  //Rest Api Function to get data from pushed by drupal
  //console.log(req.data);
  res.send('Success');
});

如何将数据从drupal发送为node.js中的jsondata

1 个答案:

答案 0 :(得分:1)

您可以从req.body获取发布的数据,例如console.log(req.body); http://expressjs.com/api.html#req.body

或者您可以使用req.param,例如console.log(req.param('data')); http://expressjs.com/api.html#req.param