2015-01-07 132 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