PHP curl request code with Content Type application/json in header

Here is the PHP curl request code with Content Type application/json in header

$url = '' ; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' )); 
          
$server_output = curl_exec($ch);
if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    //echo 'Operation completed without any errors';
}

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator