问题描述:

I want pass array in my route POST

I Did try this

my object is

var myobj = [{name:'foo',name:'bar',name:'buz'}]

and I want pass these values in this http.request

var options = {

hostname : 'myhost',

port : 'myport',

path : 'myroute',

method : 'POST',

agent : false,

body : myobj,

headers : {'Content-Length': myobj.length}

};

var req = http.request(options,function(res) {});

router.post('myroute', function( req, res ){

//I want myobj here

console.dir(req.body); //EMPTY

})

I did try also

path : 'myroute'+myobj and i recived socket hang up

I did try also

json = JSON.stringify(docs);

网友答案:
req.write(JSON.stringify(myobj));

router.post('myroute', function( req, res ){
    console.dir(req.body);
})
相关阅读:
Top