javascript - Send Array in post request using node.js using application/x-www-form-urlencoded -


i tried send post request api , post parameters should array, how send in curl

curl http://localhost:3000/check_amounts   -d amounts[]=15 \   -d amounts[]=30 

i tried in node.js using request module

request.post('http://localhost:3000/check_amounts', {         form: {                  'amounts[]': 15 ,                 'amounts[]': 30               }     }, function(error, response, body) {         console.log(body)         res.json(body);     }); 

but second amount override first 1 , api gets result following: amounts = [30]

then tried send in different way

 request.post('http://localhost:3000/check_amounts', {             form: {                      'amounts[]': [ 15 , 30]                   }         }, function(error, response, body) {             console.log(body)             res.json(body);         }); 

but result not expected amounts = [{"0":15},{"1":30}]

note : header should contains 'content-type': 'application/x-www-form-urlencoded' not 'application/json'

does 1 have solution problem?

it's quite easy if read manual of request. should replace form querystring rather object, in case should be:

amounts=15&amounts=30

the thing i'm not sure above expression works in web server. know works in java struts. if not may try amounts[]=15&amounts[]=30 instead. hope help.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -