與@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":[]}
這意味着認證工作。