使用Java的Neo4j Rest调用(非嵌入式模式)

使用Java的Neo4j Rest调用(非嵌入式模式),java,rest,post,neo4j,cypher,Java,Rest,Post,Neo4j,Cypher,我实际上在使用Neo4j中的社区插件,并试图通过java发出POST请求来查询Neo4j服务器 我总是得到一个java.io.IOException:服务器返回的HTTP响应代码:400 虽然对同一url的类似调用可以通过javascript进行,但业务逻辑建议通过java进行调用 以下是我的代码片段: String baseURL="ip_of_server"; StringBuilder builder = new StringBuilder(); try {

我实际上在使用Neo4j中的社区插件,并试图通过java发出POST请求来查询Neo4j服务器

我总是得到一个java.io.IOException:服务器返回的HTTP响应代码:400 虽然对同一url的类似调用可以通过javascript进行,但业务逻辑建议通过java进行调用

以下是我的代码片段:

String baseURL="ip_of_server";
    StringBuilder builder = new StringBuilder();
    try {
        URL url = new URL(baseURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST"); 
        connection.setRequestProperty("Content-Type", "application/json");
        OutputStream os=connection.getOutputStream();
         OutputStreamWriter writer = new OutputStreamWriter(os,Charset.forName("UTF-8"));


         System.out.println(url);
         Map<String, Object> params = new HashMap<String, Object>();
         params.put("query", "start x = node(3) return x");
         HashMap<String,String> test3= new HashMap<String,String>();
         params.put("params", test3);
         ObjectMapper temp = new ObjectMapper();

         String testString= temp.writeValueAsString(params);
         writer.write(testString);
         writer.close();
         os.close();


        String line = null;
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        while ((line = reader.readLine()) != null) {
            builder.append(line);

        }
        System.out.println("Response from server for request : " + url.toString() + " is " );
        System.out.println(builder.toString());



    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
String baseURL=“服务器的ip地址”;
StringBuilder=新的StringBuilder();
试一试{
URL URL=新URL(基本URL);
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setDoOutput(真);
connection.setDoInput(true);
connection.setRequestMethod(“POST”);
setRequestProperty(“内容类型”、“应用程序/json”);
OutputStream os=connection.getOutputStream();
OutputStreamWriter writer=新的OutputStreamWriter(os,Charset.forName(“UTF-8”);
System.out.println(url);
Map params=新的HashMap();
参数put(“查询”,“开始x=节点(3)返回x”);
HashMap test3=新的HashMap();
参数put(“参数”,test3);
ObjectMapper temp=新的ObjectMapper();
String testString=temp.writeValueAsString(参数);
write.write(testString);
writer.close();
os.close();
字符串行=null;
BufferedReader reader=新的BufferedReader(新的InputStreamReader(
getInputStream());
而((line=reader.readLine())!=null){
builder.append(行);
}
System.out.println(“来自服务器的请求响应:“+url.toString()+”is”);
System.out.println(builder.toString());
}捕获(例外e){
//TODO:处理异常
e、 printStackTrace();
}

有什么建议吗?

它需要一个解析器,因为“=”等通过编码转换为其他字符,因此neo4j抛出一个错误

我的这个问题可能会提供一些提示-到目前为止,我还没有在neo4j数据库中设置密码。在我看来,这似乎是一个问题的查询被邮寄。可能是因为有多个“=”??我可以这样进行查询,但现在我不能在查询中包含node\u auto\u index(name=“xxx”):*curl-v-H“Content Type:application/json”-d“{”query\:\“start x=node(3)return x.name\”}”url**