2015-07-10 38 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數據,在控制檯的對象。