1

我试图将数据从 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);
}

节点.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

4

1 回答 1

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

于 2013-06-04T05:05:53.233 回答