【发布时间】:2015-10-31 18:11:52
【问题描述】:
我试图使用 Node.js supertest 来测试我编写的一些 REST API。我需要发送一个等效于以下 CURL 请求的请求:
curl -X POST -F api_key=KEY -F image=@my_file http://localhost:3000/v1/upload
我尝试了以下方法,但得到了Uncaught TypeError: first argument must be a string or Buffer。
request.post('/v1/upload')
.type('form')
.field('api_key', 'abcd')
.attach('image', 'some path')
.end(function(err, res) {
res.body.error.should.equal('Invalid username/api_key.');
done();
});
我也试过这样发送:
request.post('/v1/upload')
.type('form')
.field('api_key', 'abcd')
.attach('image', 'some path')
.end(function(err, res) {
res.body.error.should.equal('Invalid username/api_key.');
done();
});
但是服务器只能解析文件上传请求,不能解析api_key。
【问题讨论】:
标签: javascript node.js supertest superagent