JSON data curl php code example
Example 1: send application/json php
$url = 'http://www.example.com/api';
$ch = curl_init($url);
$data = array(
'username' => 'codexworld',
'password' => '123456');
$payload = json_encode(array("user" => $data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Example 2: how to read data from curl php
$data = json_decode(file_get_contents('php://input'), true);