如何使用Chai Http发布对象数组

我试图用ChaiHttp这样发布一个对象数组:

agent.post('route/to/api') .send( locations: [{lat: lat1, lon: lon1}, {lat: lat2, lon: lon2}]) .end (err, res) -> console.log err, res 

它返回一个错误,如下所示:

  TypeError: first argument must be a string or Buffer at ClientRequest.OutgoingMessage.end (_http_outgoing.js:524:11) at Test.Request.end (node_modules/superagent/lib/node/index.js:1020:9) at node_modules/chai-http/lib/request.js:251:12 at Test.then (node_modules/chai-http/lib/request.js:250:21) 

events.js:141扔呃; //未处理“错误”事件^

错误:在Zlib._handle.onerror错误的标题检查(zlib.js:363:17)

我也试图像这样发布信息,就像我们对邮递员所做的一样:

 agent.post('route/to/api') .field( 'locations[0].lat', xxx) .field( 'locations[0].lan', xxx) .field( 'locations[1].lat', xxx) .field( 'locations[2].lat', xxx) .then (res) -> console.log res 

但是payload.locations被接收为未定义的。

任何想法如何通过chai-http发布对象数组?

编辑:

这是我的路线,我认为有效载荷有问题:

 method: 'POST' path: config: handler: my_handler payload: output: 'stream' 

我在这里有同样的问题。 chai-http文档似乎是错误的。 它是:

 // Send some Form Data chai.request(app) .post('/user/me') .field('_method', 'put') .field('password', '123') .field('confirmPassword', '123') 

哪个不行。 这对我工作:

 chai.request(app) .post('/create') .send({ title: 'Dummy title', description: 'Dummy description' }) .end(function(err, res) { ... } 

尝试使用.send({locations: [{lat: lat1, lon: lon1}, {lat: lat2, lon: lon2}]}) 。 因为.field('a', 'b')不起作用。

  1. body作为表单数据

     .put('/path/endpoint') .type('form') .send({foo: 'bar'}) // .field('foo' , 'bar') .end(function(err, res) {} // headers received, set by the plugin apparently 'accept-encoding': 'gzip, deflate', 'user-agent': 'node-superagent/2.3.0', 'content-type': 'application/x-www-form-urlencoded', 'content-length': '127', 
  2. 身为application/json

     .put('/path/endpoint') .set('content-type', 'application/json') .send({foo: 'bar'}) // .field('foo' , 'bar') .end(function(err, res) {} // headers received, set by the plugin apparently 'accept-encoding': 'gzip, deflate', 'user-agent': 'node-superagent/2.3.0', 'content-type': 'application/json', 'content-length': '105',