Skip to content

Bug: Body data from curlrequest become unreadable when endpoint return long data #3034

Closed
@densoooo

Description

@densoooo

Describe the bug
Body data returned from calling API using curlrequest become unreadable when the returned data is long. I can get normal json data from calling the same API if I'm using native php curl function. When the returned data is short, curlrequest will return normal json.
Sample code using curlrequest :

` $client = \Config\Services::curlrequest();

    $data = array(
		"q" => "php"
	);

    $response  = $client->get('https://api.github.com/search/repositories', [ 'query' => $data ]);
    echo $response->getBody();

`
Sample code using php curl :

`$curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://api.github.com/search/repositories?q=php',
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
    ));

    $response = curl_exec($curl);
    echo $response;`

When sending data using curlrequest the returned body become something like this :
�����[�#�u���+�~��E4��-bC�m�Ύb�{f�ýX��jtM7�������c#�6E��C�#,J�dY�D��LQaK�Z���'�\VO��>U�K^Nf%*�v� 2��3���dV� ���N�~���YΖ���h��.w������ ��hv9�D���"�W�e ۟��8Zo^F��+���m4n��'�N�5�s{���Ɏ���I�8ݴs���u4����n�&|�ݧ������~��������o씍��(i1?��/>YM&��ٖ���"Z4'��E��nq;����2��}N�2��F�x5�1�4����I$�W�͇���}�/F%���������*|�~vrw���|

CodeIgniter 4 version
v4.0.3

Affected module(s)
\Config\Services::curlrequest();

Expected behavior, and steps to reproduce if appropriate
Expected to get json data even when API return long data

Context

  • OS: Windows 10
  • Web server: Apache 2.4.35
  • PHP version : 7.4.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions