In this tutorial, you will learn how to fire curl post requests with Codeigniter. it will help to get third-party API data using curl request in Codeigniter. you can fire post request, get request, put request and delete request in curl Codeigniter 3.


Example:

<?php
    
class MyClass extends CI_Controller {
     
    /**
     * Index Page for this controller.
     *
     */
    public function simleExample()
    {
        /* API URL */
        $url = 'http://www.mysite.com/api';
             
        /* Init cURL resource */
        $ch = curl_init($url);
            
        /* Array Parameter Data */
        $data = ['name'=>'Rathorji', 'email'=>'suport@rathorji.in'];
            
        /* pass encoded JSON string to the POST fields */
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
           
        /* set the content type json */
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Content-Type:application/json',
                    'App-Key: 123456',
                    'App-Secret: 1233'
                ));
            
        /* set return type json */
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            
        /* execute request */
        $result = curl_exec($ch);
           
        /* close cURL resource */
        curl_close($ch);
    }
}

I hope it will help you...