PHP CURL Using POST Raw JSON Data

If you wanna use Content-type: application/json and raw data, seem your data should be in json format $ch = curl_init(); $headers = [ ‘x-api-key: XXXXXX’, ‘Content-Type: application/json’ ]; $postData = [ ‘data1’ => ‘value1’, ‘data2’ => ‘value2’ ]; curl_setopt($ch, CURLOPT_URL,”XXXXXX”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec … Read more