expressjs POST标题参数?
我没有张贴到正文,并且当PHP从curl文章发表时,键/值对没有出现在我看过的任何位置 – 它们在哪里?
更新:
在curl post中使用http_build_query($ parameters),因为它们在req.body中变得可用,但是看起来奇怪的是,sinatra,play和其他web api框架都处理了相同的发布数组(没有http_build_query方法),而expression就像是混蛋继子女。 谁在右边?
app.js有configuration:
app.use(express.bodyParser()); app.use(express.methodOverride());
电话:
app.post('/call/:genericUrlParam', function(req, res){ // where is 'key'/'value' pair?! console.log('headers: ' + JSON.stringify(req.headers)); console.log('body: ' + JSON.stringify(req.body)); });
该PHP看起来像:
$parameters = array ( 'key' => 'value' ); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "localhost/call/myparam"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 50); curl_setopt($curl_handle, CURLOPT_USERPWD, "username:password"); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $parameters); $buffer = curl_exec($curl_handle); $error = curl_error($curl_handle); curl_close($curl_handle); if (empty($buffer)) { return "Error: ".$error; } else { return $buffer; }
bodyParser仅当请求的Content-type
的值为application/x-www-form-urlencoded
时才从POST请求参数填充Request.body
。 如果请求没有参数或不同的内容types,Request.body对象将是未定义的。