2015-07-10 60 views
-1

我有类似下面的API:解析阵列PARAMS在快速

curl https://apps.fundamerica.com/api/offerings \ 
-u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: \ 
-X POST \ 
-d amount="5000000" \ 
-d description="A+really+big+deal." \ 
-d max_amount="5500000" \ 
-d min_amount="4500000" \ 
-d name="Big+Deal" \ 
-d entity[city]="New+York" \ 
-d entity[country]="US" \ 
-d entity[email]="john.johnson%40johnson.com" \ 
-d entity[name]="Johnson%2C+Johnson%2C+Johnson+%26+Johnson" \ 
-d entity[phone]="12025551212" \ 
-d entity[postal_code]="10005" \ 
-d entity[region]="NY" \ 
-d entity[street_address_1]="60+Wall+St." \ 
-d entity[tax_id_number]="999999999" \ 
-d entity[type]="company" \ 
-d entity[executive_name]="John+Johnson" \ 
-d entity[region_formed_in]="NY" 

,我需要正确地解析在表达这些阵列PARAMS。你知道如何正确解析它们吗?

+1

您可能会发现['bodyparser'模块](https://github.com/expressjs/body-parser)有用 – Curious

回答

1

Make make Express能够处理POST请求,您应该使用第三方模块之一body-parser

首先,安装它:

npm install body-parser 

这里是你如何使它发挥作用:

var express = require('express'); 
var bodyParser = require('body-parser'); 
var app = express(); 

app.use(bodyParser.urlencoded({extended: false})); 

app.post('/api/offerings', function(req, res) { 
    console.log(req.body); 
    res.send('Parsed'); 
}); 

app.listen(1337); 

你会得到整个POST数据,在控制台的对象。