Java 我可以´;我不能为我的POST请求连接

Java 我可以´;我不能为我的POST请求连接,java,rest,neo4j,Java,Rest,Neo4j,我使用triying将我的projecto连接到Neo4j数据库,我可以在执行GET请求时执行,但使用相同的代码(将GETMethod更改为POSTMethod)我无法执行 这是我的代码: 字符串名称=“xxx”; 字符串密码=“xxx” 但有一个HttpException 这是我第一次使用Rest和Neo4j 有人能帮我吗 谢谢。答案如下: 尝试使用DefaultHttpClient,如果这不能解决问题,也可以尝试使用HttpPost而不是HttpMethod HttpClient clien

我使用triying将我的projecto连接到Neo4j数据库,我可以在执行GET请求时执行,但使用相同的代码(将GETMethod更改为POSTMethod)我无法执行

这是我的代码:

字符串名称=“xxx”; 字符串密码=“xxx”

但有一个HttpException

这是我第一次使用Rest和Neo4j

有人能帮我吗

谢谢。

答案如下:

尝试使用DefaultHttpClient,如果这不能解决问题,也可以尝试使用HttpPost而不是HttpMethod

HttpClient client = new DefaultHttpClient();       
String url = "http://localhost:7474/db/data/cypher";

HttpPost method = new HttpPost(url);

//You can use StringEntity for your query
StringEntity params= new StringEntity("your query goes here", ContentType.APPLICATION_JSON);
method.setEntity(params);

//for the response use followings
HttpResponse response = client.execute(method);
HttpEntity entity = response.getEntity();

“但是有一个HttpException”--那么,你打算和我们共享这个异常和堆栈跟踪吗?你想让我们猜出问题出在哪里吗?另外,请告诉我们代码中的哪个语句引发异常。我可以解决它,谢谢。
HttpClient client = new DefaultHttpClient();       
String url = "http://localhost:7474/db/data/cypher";

HttpPost method = new HttpPost(url);

//You can use StringEntity for your query
StringEntity params= new StringEntity("your query goes here", ContentType.APPLICATION_JSON);
method.setEntity(params);

//for the response use followings
HttpResponse response = client.execute(method);
HttpEntity entity = response.getEntity();