‘John Doe’,
’email’ => ‘johndoe@example.com’
);
// URL of the server endpoint
$url = ‘https://example.com/api/post’;
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen(json_encode($postData)))
);
// Execute cURL session
$response = curl_exec($ch);
// Check for errors
if(curl_errno($ch)){
echo ‘Curl error: ‘ . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Print response
echo $response;
?>