gpt4 book ai didi

java - Neo4j - 服务器返回 HTTP 响应代码 : 500 for URL: http://localhost:7474/db/data/cypher

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:37 25 4
gpt4 key购买 nike

我在使用 HTTPConnection 运行 cypher 时遇到异常。

服务器返回 HTTP 响应代码:500,URL:http://localhost:7474/db/data/cypher

public class HTTPConnectionTest {
public static void main(String[] args) throws Exception {
try {
System.out.println("Testing HTTPConnection");
StringBuffer responseString = new StringBuffer();
String url = "http://localhost:7474/db/data/cypher";

//String query = "match (user:USER{id:\'Sree\'}) return user ";
String query = "match (user:USER{id:\"Sree\"}) return user ";
URL neo4jUrl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) neo4jUrl
.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestProperty("Content-Type", "application/json");
String urlParameters = "{\"query\":\"" + query + "\"}";
httpConn.setRequestProperty("Accept",
"application/json; charset=UTF-8");

DataOutputStream wr = new DataOutputStream(
httpConn.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

BufferedReader in = new BufferedReader(new InputStreamReader(
httpConn.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null) {
responseString.append(inputLine);
}
System.out.println("Out put " + responseString);
in.close();
} catch (Exception e) {
System.out.println("Exception" + e.getMessage());
}
}
}

如果我用单引号传递密码中的值,它就会工作并获取输出对象。

字符串查询=“match(user:USER{id:\'Sree\'})返回用户”;

有什么建议吗?预先感谢您!

最佳答案

这对我来说看起来很愚蠢。

代码中的一个小变化。将参数转换为 JSONObject 字符串

JSONObject jsonObject = new JSONObject();
jsonObject.put("query", query);
String urlParameters = jsonObject.toString();

而不是

String urlParameters = "{\"query\":\"" + query + "\"}";

关于java - Neo4j - 服务器返回 HTTP 响应代码 : 500 for URL: http://localhost:7474/db/data/cypher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com