【发布时间】:2015-02-06 16:57:08
【问题描述】:
我在使用 HTTPConnection 运行密码时遇到异常。
服务器返回 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());
}
}
}
如果我用单引号在密码中传递值,它正在工作并获取输出对象。
字符串查询 = "匹配 (user:USER{id:\'Sree\'}) 返回用户 ";
有什么建议吗?提前谢谢!
【问题讨论】: