2013-05-07 38 views
0

我实际上使用Neo4j中的社区插件,并尝试通过java发出POST请求来查询neo4j服务器。Neo4j其余调用使用Java(不在嵌入式模式)

我总是得到一个java.io.IOException:服务器返回的HTTP响应代码:400 虽然类似的调用通过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(); 
    } 

有什么建议?

+0

我的这个问题可以提供一些提示 - http://stackoverflow.com/questions/15260994/error-401-unauthorized-for-neo4j-rest-url-on-heroku – Gopi 2013-05-07 17:19:44

+0

我现在还没有在neo4j db中设置密码。在我看来,查询是在POST中发送的问题。难道是因为多个“=”? – neoeahit 2013-05-07 17:35:44

+0

我可以做这样的查询,但现在我不能在查询 :** curl -v -H“Content-Type:application/json”-d“{\”查询中包含node_auto_index(name =“xxx”) \“:\”start x = node(3)return x.name \“}”“url”** – neoeahit 2013-05-09 15:42:23

回答

0

什么它需要是一个分析器,因为“=”等由编码转换成其他字符,因此Neo4j的引发错误

相关问题