如何在http传递数组.请求节点

How Can I Pass Array in http.request node?

本文关键字:数组 请求 节点 http      更新时间:2023-09-26

我想传递数组在我的路由POST

I Did try this

my object is

var myobj = [{name:'foo',name:'bar',name:'buz'}]
我想在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);
})