2012-04-18 31 views
2

几个月前,下面的代码完美工作,并用于在couchdb(iriscouch)中添加新文档。在Couchdb(iriscouch)中添加新文档POST请求失败,状态为500

现在我得到一个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: [email protected] 

回答

2

貌似http://www.iriscouch.com/是向下的那一刻:

Host not found: www.iriscouch.com 
+0

试过。似乎要起来,但。 – sbose 2012-04-18 11:44:47

+1

+1为了获得最大的健壮性,您的代码可以重试500次,因为它们通常是暂时的(只有几秒钟) – JasonSmith 2012-04-18 11:56:39

+0

是的,页面重新开始。你还有同样的问题吗? – PiTheNumber 2012-04-18 12:21:43

2

有你考虑使用抽象层,在文件做什么HTTP?

你的代码将会有大量的HTTP代码,如果你不:)

我个人写和维护的node.js这是基于CouchDB的客户端请求,如果您对此感到好奇,可以在github

+0

啊,可爱的感谢链接:) – sbose 2012-04-18 12:35:27

相关问题