• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curl lib response getBody return binary string

#1
Today I'm trying to fetch some testing data from "https://jsonplaceholder.typicode.com/todos/1",
but when I get a response and try to get data it will give binary string.

Code:
        $this->client = \Config\Services::curlrequest([
            'base_uri' => 'https://jsonplaceholder.typicode.com'
        ]);

        $data = $this->client->get('/todos/1');

        d( $data->getBody() ); // also try getJSON()

output:

Code:
���RPP*-N-�LQ�R0�q3̒̒�T%+��Ԝ���b���N�U+H��-�I-IiIK�)N�7��S

is anything I'm doing wrong.

EDIT:

I'm trying to get data in json or array format from api.

ALREADY TRIED THINGS: 

Code:
        $data = $this->client->get('/todos/1');

        dd( $data->getBody() ); // give binary string,

        dd( json_decode( $data ) ); // error: json_decode() expects parameter 1 to be string, object given

        dd( $data->getJSON() ); // error: Failed to parse json string, error: "Malformed UTF-8 characters, possibly incorrectly encoded".
Reply

#2
Did you try this?

PHP Code:
$data json_decode($this->client->get('/todos/1')); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.