curl -> node, how to?

谁都会走 提交于 2019-12-12 01:43:14

问题


I need to set the password for Neo4j and can do it from the command line like this:

curl -H "Content-Type: application/json" \
   -H "Authorization: Basic `echo -n 'neo4j:neo4j' | base64`" \
   -X POST -d '{"password":"nopass"}' \
   http://localhost:7474/user/neo4j/password

but I'm now trying to do it in node.js like this:

var f = require('node-fetch');
var url = 'http://neo4j:n0p4ss@localhost:7474/user/neo4j/password';
var auth = new Buffer('neo4j:neo4j').toString('base64');
f(url, {
    method: 'POST',
    body: {'password': 'nopass'},
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + auth
    }   
})
.then(res => res.text())
.then(txt => { console.log(txt); });

however, what I get back is:

{
  "errors" : [ {
    "code" : "Neo.ClientError.Request.InvalidFormat",
    "message" : "Required parameter 'password' is missing."
  } ]
}

which to me means the body: {...} isn't getting sent correctly. can anyone see what's wrong with my code?


回答1:


ah. figured it out. it needs:

body: JSON.stringify({'password': 'nopass'}),


来源:https://stackoverflow.com/questions/38540095/curl-node-how-to

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!