2011-05-25 93 views
0

我想通过HTTP API使用Neo4js Traverser。 如果我通过curl在命令行中使用它,它工作正常,但是当我尝试通过PHP使用curl时,我始终得到一个错误。Neo4j使用Traverser通过REST HTTP

这是curl命令:

curl -H Accept:application/json -H Content-Type:application/json -X POST -d '{"order":"depth first"}' http://localhost:7474/db/data/node/5/traverse/node 

这是我的PHP代码:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://localhost:7474/db/data/node/5/traverse/node"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept:application/json', 
    'Content-Type:application/json' 
)); 
curl_setopt($ch, CURLOPT_POSTFIELDS, '"{"order": "depth first"}"'); 

$output = curl_exec($ch); 

echo '<pre>'; 
var_dump(curl_getinfo($ch)); 
var_dump($output); 

curl_close($ch); 

这是错误我得到:

HTTP错误500

访问 /db/dat时出现问题一个/节点/ 5 /横动/节点。原因:

java.lang.String cannot be cast to java.util.Map 

什么想法?

回答

1

看起来你有JSON字符串之前的报价:

curl_setopt($ch, CURLOPT_POSTFIELDS, '"{"order": "depth first"}"'); 

可能要试试这个:

curl_setopt($ch, CURLOPT_POSTFIELDS, '{"order": "depth first"}'); 

编辑:虽然更好,但我会用json_encode与关联阵列以确保在必要时正确转义:

$json_data = array("order" => "depth first"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json_data)); 
+0

感谢您的提示,现在它的作品! – prehfeldt 2011-05-25 12:00:16