How to Post JSON Data with PHP cURL & Receive It?
Hi! Here let's see how to post json data with php curl and receive the raw json sent . You can simply use PHP file_get_contents() to send HTTP GET request . But it's not the same case with HTTP POST. Fortunately PHP cURL makes the process very simple. With curl you can easily send HTTP requests. In case you don't know, 'cURL' is a library that let you communicate with web servers using different protocols such as http, https, ftp, telnet, file etc. To use curl, you must install libcurl package on your server according to the version of PHP you use. In case you are not sure if curl is enabled on your machine or not, use this code to check it. <?php echo (is_callable('curl_init') ? 'cURL is enabled' : 'cURL is disabled'); ?> How to Post JSON with PHP cURL? In order to send HTTP POST request with JSON data, you have to follow some steps and they are, Format JSON data correctly Attach JSON to the body of the POST request Set th...