我正在尝试将文档插入 CouchDB。执行此代码时,CouchDB 返回以下错误:
STATUS: 400
BODY: {"error":"bad_request","reason":"invalid_json"}
我的代码:
var http = require('http')
var options = {
"host": "localhost",
"port": "5984",
"path": "/chinese",
"headers": {"content-type": "application/json"},
"method": "PUT",
"body": JSON.stringify({
"_id":"rabbit",
"_rev":"2-c31d8f403d44d1082b3b178ebef8d329",
"Subject":"I like Plankton"
})
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.write('data\n');
req.end();
怎么了?
编辑:我需要更新数据,所以我将 POST 替换为 PUT。