• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Response data from curlrequest() vs curl_init() encoding

#1
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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