[php-src] Issue #7935: Error php-curl request with query params
| From: | iluuu1994 | Date: | Wed, 12 Jan 2022 15:42:24 +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-238986@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7935
Comment Author: iluuu1994
@ejgutierrez74 As @kamil-tekiela mentioned,
http_build_query encodes your input.
https://3v4l.org/Oakob#v8.1.1
```php
// These two are roughly equivalent (single encoding)
var_dump(http_build_query([
'scope' => 'tweet.read users.read offline.access',
]));
//> string(42) "scope=tweet.read+users.read+offline.access"
var_dump('scope=' . urlencode('tweet.read users.read offline.access'));
//> string(42) "scope=tweet.read+users.read+offline.access"
// These two are roughly equivalent (double encoding)
var_dump(http_build_query([
'scope' => urlencode('tweet.read users.read offline.access'),
]));
//> string(46) "scope=tweet.read%2Busers.read%2Boffline.access"
var_dump('scope=' . urlencode(urlencode('tweet.read users.read
offline.access')));
//> string(46) "scope=tweet.read%2Busers.read%2Boffline.access"
```
To get the same encoding behavior as rawurlencode you can also pass specify the
$encoding_type parameter. https://www.php.net/manual/en/function.http-build-query.php
https://3v4l.org/65Aer#v8.1.1
```php
var_dump(http_build_query([
'scope' => 'tweet.read users.read offline.access',
], encoding_type: PHP_QUERY_RFC3986));
//> string(46) "scope=tweet.read%20users.read%20offline.access"
```
Do these options work for you?