2013-06-04 32 views
1

我試圖從Drupal的頁面數據發送到節點如何在node.js中提取POST參數?

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的發送作爲節點jsondata。 js

+0

是否使用expressjs框架使用req.param,例如? – Joonas

+0

是的,我正在使用Express – Okky

+1

您確定您使用'express.bodyparser'嗎?您需要這樣才能訪問POST編輯參數。 – user568109

回答