[php-src] Issue #7935: Error php-curl request with query params
| From: | KapitanOczywisty | Date: | Thu, 13 Jan 2022 19:01:38 +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-239004@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7935
Comment Author: KapitanOczywisty
%2520 is double encoded space, once from rawurlencode and once from
http_build_query.
> Not at all, because twitter api works that only scope should be rawurlencoded, not the other
> params.
Any parameters can be encoded with urlencode - tweeter api doesn't care about that. The plus
sign might be problematic, but this can be solved with PHP_QUERY_RFC3986 as mentioned
above. Try following code and make sure it really doesn't work:
```php
$params = array('response_type' => 'code',
'client_id' => $client_id,
'redirect_uri' => $redirect_uri,
'scope' => $scope,
'state' => $state,
'code_challenge' => $code_challenge,
'code_challenge_method' => 'plain' );
$url = $endpoint . '?' . http_build_query($params, "", null, PHP_QUERY_RFC3986);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
```
You can also use composer package like:
[abraham/twitteroauth](https://packagist.org/packages/abraham/twitteroauth)