与@hydraruiz意见分歧的事,我想你正在运行一个Neo4j的2.2.0-M0x号版本。这个默认启用了身份验证。您首先需要提供您的用户名和密码来获取令牌。
curl -H "Content-Type: application/json" -d '{"username":"neo4j", "password":"mypassword"}' http://localhost:7474/authentication
{
"username" : "neo4j",
"password_change" : "http://localhost:7474/user/neo4j/password",
"password_change_required" : false,
"authorization_token" : "53eaa48a972439012868a8d5463e0c3d",
"authorization_token_change" : "http://localhost:7474/user/neo4j/authorization_token"
}
对REST API的后续调用使用授权标头中的令牌。根据文档,http授权标头的值为Basic realm="Neo4j"
加上以冒号为前缀的base64编码标记。我们可以使用命令行工具:echo -n ":tokenstring" | base64
。为了简单起见,我发出一个简单的暗号声明match (n) return count(n)
:
curl -H "Authorization: Basic realm=\"Neo4j\" `echo -n ":53eaa48a972439012868a8d5463e0c3d" | base64`" \
-H "Content-Type: application/json" \
-d '{"statements":[{"statement":"match (n) return count(n)"}]}' \
http://localhost:7474/db/data/transaction/commit
回报:
{"results":[{"columns":["count(n)"],"data":[{"row":[0]}]}],"errors":[]}
这意味着认证工作。