在Couchdb中添加新文档(iriscouch)POST请求因状态500而失败

时间:2012-04-18 11:36:45

标签: javascript http node.js couchdb

几个月前,下面的代码完美无缺,用于在couchdb(iriscouch)中添加新文档。

现在我收到了HTTP状态500.是否有解决方法?

代码(在Node.js中):

var http=require('http');

var options = {
  host: 'sbose78.iriscouch.com',
  path: '/bosedb1',
  method: 'POST',

  headers:{
 'Content-Type':'application/json',
 'accept':'application/json'
   }
 };

var data={
   'servings' : 4,
   'subtitle' : "Delicious with fresh bread",
   'title' : "Fish Stew------"
};

var req = http.request(options, function(res) {
   console.log('STATUS: ' + res.statusCode);
   console.log('HEADERS: ' + JSON.stringify(res.headers));
     var body="";

   res.on('data', function (chunk) {
     body+=chunk;
         console.log('BODY(inside listener):\n ' + body);

   }); 

  console.log('BODY (outside listener): ' + body);

});


req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});



 //write data to request body
req.write(JSON.stringify(data));
req.end();

回应:

    STATUS: 500
HEADERS: {"content-type":"text/plain","content-length":"239"}
BODY(inside listener):
 Internal routing error

Sorry, we cannot connect to the intended server.

We have just been notified of this problem. We will correct it as soon as possible.

Feel free to contact us if you have any questions: support@iriscouch.com

2 个答案:

答案 0 :(得分:2)

目前看来http://www.iriscouch.com/已关闭:

Host not found: www.iriscouch.com

答案 1 :(得分:2)

您是否考虑过使用抽象层,至少要做http?

如果不这样做,你的代码库会有很多http代码:)

我个人编写并维护了基于请求的node.js CouchDB客户端,如果您对此感到好奇,可以在github找到更多信息