I can't send JSON encoded data via PHP & cURL
my sender code is:
$id = 1;
$txt = "asdsad";
$txt2 = "baszama";
$data = array("id" => "$id", "txt" => "$txt", "txt2" => "$txt2");
$data_string = json_encode($data);
$ch = curl_init('index.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
index.php:
var_dump($_REQUEST);
My recerieved data:
array(0) { }
What's the problem in my code?