[php-src] Issue #7935: Error php-curl request with query params
| From: | ejgutierrez74 | Date: | Wed, 12 Jan 2022 13:22:32 +0000 |
| Subject: | [php-src] Issue #7935: Error php-curl request with query params | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238981@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7935
Author: ejgutierrez74
### Description
In the Twitter API...
The following code:
```
$url = $endpoint . '?' . 'response_type=' . 'code'
. '&client_id=' . $client_id
. '&redirect_uri=' . rawurlencode($redirect_uri)
. '&scope=' . rawurlencode($scope)
. '&state=' . $state
. '&code_challenge=' . $code_challenge
. '&code_challenge_method=' . 'plain';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
```
but this one doesnt work…and in my opinion should work:
```
$params = array('response_type' => 'code',
'client_id' => $client_id,
'redirect_uri' => rawurlencode($redirect_uri),
'scope' => rawurlencode($scope),
'state' => $state,
'code_challenge' => $code_challenge,
'code_challenge_method' => 'plain' );
$url = $endpoint . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
```
Resulted in this output:
``The first call co curl works, but the second doesnt..
```
But I expected this output instead:
``````Both requests are equivalent, so they have to return the same....
```
### PHP Version
PHP 7.4
### Operating System
_No response_