expressjs POST头参数?

时间:2011-08-27 08:39:39

标签: javascript post node.js express

我没有张贴到正文,并且在从PHP发送卷曲帖子时我看到的任何地方都没有显示键/值对 - 它们在哪里?!

更新

在curl post中使用http_build_query($ parameters),因为它们在req.body中可用,但是看起来很奇怪sinatra,play和其他web api框架都处理发布的数组相同(w / o http_build_query方法),表达似乎是混蛋继子。谁在右边?

app.js有config:

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;
        }

1 个答案:

答案 0 :(得分:1)

仅当请求的标头Request.body具有值Content-type时,

bodyParser才会从POST请求参数中填充application/x-www-form-urlencoded。如果请求没有参数或不同的内容类型,则Request.body对象将是未定义的。