2015-01-07 134 views
2

我在使用cURL作为HTTP clinet和Neo4j时遇到了问题。 当我写这篇文章的命令:curl http://localhost:7474/db/data/(或任何URL,如http://localhost:7474/db/data/node/然后我得到的JSON格式结果如下:cURL命令 - Neo4j

{ "errors" : [ { 
    "message" : "No authorization token supplied.", 
    "code" : "Neo.ClientError.Security.AuthorizationFailed" } ], "authentication" : "http://localhost:7474/authentication" } 

回答

4

与@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":[]} 

这意味着认证工作。

2

您还可以disable authorization。在conf/neo4j-server.properties文件中:

# Require (or disable the requirement of) auth to access Neo4j 
dbms.security.auth_enabled=false