Welcome Guest, Not a member yet? Register   Sign In
Response data from curlrequest() vs curl_init() encoding
#1

(This post was last modified: 05-24-2020, 08:26 AM by JohnDoe.)

Hi, I'm trying to call 3rd party API using CURLRequest Class. But the body result is different compared by using PHP curl_init().  
My function using curlrequest() :
PHP Code:
function getList($page 1$limit 10$search null)
    {
        
$client = \Config\Services::curlrequest([
            'base_uri' => self::API_BASE_URI
        
]); 

        $data = array(
            
"application_id" => APP_ID,
            
"language" => self::API_LANG,
            
"limit" => $limit,
            
"page_no" => $page,
            
"search" => $search,
        );
        
        $response  
$client->get('list/', [ 'query' => $data ]);
        echo $response->getStatusCode();
        echo $response->getBody();
        echo $response->getHeader('Content-Type');
        return;
    

My function using curl_init() :
PHP Code:
function getList2($page 1$limit 10$search null)
    {
        $curl curl_init();

        $data = array(
            
"application_id" => APP_ID,
            
"language" => self::API_LANG,
            
"limit" => $limit,
            
"page_no" => $page,
            
"search" => $search,
        );

        curl_setopt_array($curl, array(
            CURLOPT_URL => self::API_BASE_URI 'list/',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
            CURLOPT_POSTFIELDS => http_build_query($data),
        ));

        $response curl_exec($curl);
        $arr_response json_decode($response);

        echo json_encode($arr_response->data);
    
Using curl_init(); I can get json data as a response. But using curlrequest() my response body is

Code:
����o�0���K��Ď��J�P�VmU^c�מwSU��mp�8�i7��� ��D������>���[XZa�%L�y��V�t f�-L1 �5V(�rF�^��t�]3��|�u-�+Y��-Ե, )��� �Ga���+��y���h��b���h���b%�c����C�F�]О��L��w.fӚ�mAW\�a��(ՎJ�(�M�㰢^�&5��W� �vBBh!����Y��D#��ƅ��3���D�(�I���1"��]N�G?3u��5�R�,�Ƭ[B1�i��&�bv�^��Υ�dqk ��sQ�ڍoI1�g�(�ZQ؝�z�߸�=# :`��F�,�OeS~2 Ie=�G�뮭�̦n���-Q�m�$ CJ������ΎVs_j А��5�+`0���+S 0���`����������O�|�u�}�����|��7��+��q
Reply




Theme © iAndrew 2016 - Forum software by © MyBB