I have the following problem. This data in this structure
$transfer = {stdClass} [4]
module = "Member"
action = "create"
token = null
params = {stdClass} [3]
username = "Test"
email = "test@test.com"
password = "Test"
has to be send vi REST to the REST Server.
Therefore I encode the data with json_encode ($object). The decoded object looks like this:
{"module":"Member","action":"create","token":null,"params":{"username":"Test","email":"test@test.com","password":"Test"}}
For testing purpose I decode the encoded result to see if everything works fine. Which gives me the object correct back.
When I transfer the data via curl, the server receives this json_encoded data:
{"module":"Member","action":"create","token":null,"params":{"username":"Test","email":"test@test.com" = ""
And finally the json_decode($request) ands up with the following error:
json_decode() expects parameter 1 to be string, array given
The curl code for this is:
$curl = curl_init($url);
// prepare curl for Basic Authentication
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$curl_post_data = json_encode($postdata);
$test = json_decode($curl_post_data); // for testing
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); <= $postdata = $transfer the object/array mentioned above
$curl_response = curl_exec($curl);
curl_close($curl);
What's wrong? Why it is not possible to decode the encoded data after the curl exec to the REST Server?