Good afternoon, tell me how to send your JSON in the request body, there is a standard script

<?php /** * http://www.php.net/manual/ru/function.curl-exec.php */ /** * Send a POST request using cURL * @param string $url to request * @param array|string $post values to send * @param array $options for cURL * @internal param array $get * @return string */ function curl_post($url, $post = null, array $options = array()) { $defaults = array( CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_SSL_VERIFYHOST =>0,//unsafe, but the fastest solution for the error " SSL certificate problem, verify that the CA cert is OK" CURLOPT_SSL_VERIFYPEER=>0, //unsafe, but the fastest solution for the error " SSL certificate problem, verify that the CA cert is OK" CURLOPT_POSTFIELDS => $post ); $ch = curl_init(); curl_setopt_array($ch, ($options + $defaults)); if( ! $result = curl_exec($ch)){ trigger_error(curl_error($ch)); } curl_close($ch); return $result; } 

and I need to this address

 curl_post("https://iiko.biz:9900/api/0/orders/add?access_token=$access_token&requestTimeout=10000"); 

Add more your JSON, how to do it?) Thanks in advance!

    1 answer 1

    You need to add the correct CURLOPT_HTTPHEADER . You can like this:

     <?php $url = 'https://iiko.biz:9900/api/0/orders/add?access_token=$access_token&requestTimeout=10000'; $ch = curl_init($url); $jsonDatas = array( 'key' => 'value', 'key2' => 'value2' ); $jsonDatasEncoded = json_encode($jsonDatas); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); ?> 
    • thanks, what you need!) - Sergey Kozin