当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How Can I Pass Array in http.request node?

问题描述:

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);
})
分享给朋友:
您可能感兴趣的文章:
随机阅读: