-1
I have a problem to make a POST request directly from PHP to REST, because the data does not arrive in JSON format.
{"status":"ok","result":{ "user"{"id":"xxx","username":"xxx","email":"xxx","limit_of_sessions":1,"strategy_of_sessions":"xxx","type":"xxx"},"token":"xxxx"} }
But when I take the value of the object it returns the value 1 or true.
<?php
$url = url;
$fields = array("login"=>"xxx","password"=>"xxx");
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8'
));
$result = curl_exec($ch);
print_r( "Resultado ".$result[0]['status']);
curl_close($ch);
I have tried using Json_encode() or Json_decode() and nothing.
it seems to me that you are converting into json only the $Fields when you should actually convert the result
– Marcos Vinicius
That’s right, Marcos. I used $formatedResponse = '['. $result. ']'; and it was. Thank you so much for your help.
– Gabriel Souza
Done, Thank you!
– Gabriel Souza
thanks, for nothing!
– Marcos Vinicius