PHP Requests Library within Codeigniter

前端 未结 5 2450
孤独总比滥情好
孤独总比滥情好 2021-02-20 06:52

I\'m using the requests library (http://requests.ryanmccue.info/) for PHP.

I installed composer and added the following Json configuration in composer.json

5条回答
  •  孤城傲影
    2021-02-20 07:19

    I will just add some points to a well-written answer by Gopkumar Gopalan to make it work in codeigniter 3.x.

    Step 1

    Add the Requests library in your composer.json

    Step 2

    Install dependencies composer install

    Step 3

    Create a file PHPRequests.php in {codeigniter_directory}/application/libraries with this content (Note there is a change in the path of the requests library)

    Step 4

    In your controller you can use Requests by loading PHPRequests library we created in previous step.

    $this->load->library('PHPRequests');
    

    Like this test function

    public function test()
    {
        $this->load->library('PHPRequests');
        $response = Requests::get('https://github.com/timeline.json');
        var_dump($response->body);
    }
    

    Hope it helps someone

提交回复
热议问题