【发布时间】:2016-07-31 12:45:11
【问题描述】:
我正在尝试使用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'
【问题讨论】:
-
@Cuthbert,没有。
field方法接受字符串作为第二个参数。我改用JSON.stringify并发表了我的帖子。但是我发现主要问题是超级代理或有效负载输出。