Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
densoooo opened this issue May 25, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@densoooo
Copy link

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
@densoooo densoooo added the bug Verified issues on the current code behavior or pull requests that will fix them label May 25, 2020
@densoooo
Copy link
Author

Apparently the problem was caused by the curl on vendor\codeigniter4\framework\system\HTTP\CURLRequest.php having Accept-Encoding: gzip, deflate, br on the CURLOPT_HTTPHEADER. Removing Accept-Encoding from header or adding CURLOPT_ENCODING with empty value to $curl_options will solve the problem with long json data

@CatAnonymous
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants