我試圖將文檔插入到CouchDB中。雖然執行此代碼的CouchDB返回以下錯誤:嘗試從Node.js將文檔插入到CouchDB時出現'bad_request invalid_json'錯誤
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。
這是CouchDB返回錯誤消息,而不是Node.js – 2012-07-26 07:02:47