2011-05-25 7 views
0

J'essaie d'utiliser Neo4js Traverser via l'API HTTP. Si je l'utilise via curl sur la ligne de commande cela fonctionne très bien, mais quand j'essaie de l'utiliser via curl via PHP, je reçois une erreur tout le temps.Neo4j utilisant Traverser via REST HTTP

C'est commande 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 

Et voici mon code 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); 

Ceci est l'erreur que je reçois:

ERREUR HTTP 500

Problème d'accès à /db/dat a/noeud/5/traverse/noeud. Raison:

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

Des idées?

Répondre

1

On dirait que vous avez des citations avant la chaîne JSON:

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

voudrez peut-être essayer ceci:

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

EDIT: Bien mieux encore, j'utiliser json_encode avec associative tableau pour assurer une bonne évasion si nécessaire:

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

Merci pour le conseil, maintenant ça marche! – prehfeldt

Questions connexes