小编Tom*_*Tom的帖子

使用Java Neo4j Rest Api进行身份验证以访问服务器

我开始使用Neo4j Rest Api但是当我尝试连接服务器时出现以下错误:

{
  "errors" : [ {
    "code" : "Neo.ClientError.Security.AuthorizationFailed",
    "message" : "No authorization header supplied."
  } ]
}
Run Code Online (Sandbox Code Playgroud)

这个错误似乎是正常的,因为我在使用请求时没有对服务器进行身份验证.在Neo4j 2.2.2手册(http://neo4j.com/docs/stable/rest-api-security.html)中我读过我收到此错误的原因是:

请求应包含Authorization标头,其值为Basic,其中"payload"是base64编码的"username:password"字符串. 示例请求GET http:// localhost:7474/user/neo4j 接受:application/json; charset = UTF-8授权:基本bmVvNGo6c2VjcmV0

但我无法摆脱这个错误,因为我不知道如何在我的请求中包含标题!以下是我的代码中的请求示例:

WebResource resource = Client.create().resource( nodeEntryPointUri );   
ClientResponse response = resource.accept( MediaType.APPLICATION_JSON )
                .type( MediaType.APPLICATION_JSON )
                .entity( "{\"data\" : \"nex\"}" )
                .post( ClientResponse.class );      
response.close();
Run Code Online (Sandbox Code Playgroud)

因此,如果有人可以帮我根据我的要求对服务器进行身份验证,那可能会非常有帮助!

谢谢

java rest neo4j

2
推荐指数
1
解决办法
1034
查看次数

标签 统计

java ×1

neo4j ×1

rest ×1