Skip to content

Instantly share code, notes, and snippets.

@niklasfi
Created February 13, 2011 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niklasfi/824790 to your computer and use it in GitHub Desktop.
Save niklasfi/824790 to your computer and use it in GitHub Desktop.
this throws an error:
var req = http.request({host: '127.0.0.1', port: '5984', path: '/ms/', method: 'POST', 'Content-Type': 'application/json'},function(res){
var sigma = '';
res.on('data',function(chunk){sigma+=chunk})
res.on('end',function(){
console.log(sigma); //{"error":"bad_content_type","reason":"Content-Type must be application/json"}
var reply = JSON.parse(sigma);
if(reply.ok == "true")
callback(reply.id);
else
callback(null);
})
});
var data= JSON.stringify({'type':'file','modul':doc._id,'author': author, 'downloads':0})
console.log(data); //{"type":"file","modul":"28d946b681df8ab17c2010193e001172","author":"Niklas Fischer","downloads":0}
req.end(data);
root@vs1145146:/var/www/mitschriften# curl -X POST -H "Content-Type: application/json" -d '{"type":"file","modul":"28d946b681df8ab17c2010193e001172","author":"Niklas Fischer"wnloads":"0"}' 127.0.0.1:5984/ms/
{"ok":true,"id":"28d946b681df8ab17c2010193e004bf9","rev":"1-5ffe477691071504ca55bfa9fb997dd4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment