Answer the question
In order to leave comments, you need to log in
Execute cURL request from PHP?
Hey!
There is such a cURL request:
curl -H Content-Type:application/json -X PUT -d 'the_value' localhost :7474/db/data/node/123/properties/foo
Actually, the problem is that the transmitted data is a string , not a JSON object... The Neo4j server doesn't like that very much.
How can I make such a request from php? No matter how I tried - error 500.
Please tell me which curl_setopt should be placed in order to make such a request?
Answer the question
In order to leave comments, you need to log in
Understood. First, the Neo4j server itself is very strict about incoming data. Therefore, the string had to be packed like this: '"some string"\n'
Further, the request should be made with sending the file. At least that's how it turned out, and that's enough)
$filename = 'test/tempfile'; //открываем темповый файл
$dataToPut = $_POST['dataToPut']; //Извлекаем из поста данные
$url = $_address; //урл
$fh = fopen('test/tempfile', 'w+');
if ($fh == false)
{
//echo("false");
}
fwrite($fh, $dataToPut); //Загоняем строку в файл
fseek($fh, 0);
$ch = curl_init();
curl_setopt($ch, CURLOPT_INFILE, $fh);
//curl_setopt($ch, CURLOPT_INFILESIZE, $length);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_PUT, 4);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: application/json', 'Expect: '));
$response = curl_exec($ch);
fclose($fh);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status;
As far as I understand JSON, JSON is a string and it is not an object, just like XML is a string. Maybe the problem is somewhere else? Or is your JSON not valid? Can't see server logs? I think there might be an answer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question