Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set query parameters with same name as Guzzle?

Tags:

php

guzzle

I have no problem setting query parameters in Guzzle. But I can't add parameters with the same name. My query params array is below.

$query_params = array(
                'test' => 'abc',
                'test2' => true,
                'limit' => 10,
                'item_id' => '8159'
            );

I want the query parameters to be as follows.

?test=abc&test2=true&limit=10&item_id=8159&item_id=333&item_id=435&item_id=123..

I want to duplicate the item_id parameter as above. And I tested as follows, but this time a bad request was returned from the service. When I looked at the link, I saw that the '=' symbols turned into strange strings like 5BD0%. There was no problem in other parameters. But that's what happened to those with the same name.

...'item_id' => array('123','3243','243')...

The guzzle setting is as follows:

 $response = $this->client->request('GET', $endpoint, array(
                    'headers' => array(
                        'X-API-KEY' => KEY
                    ),
                    'query' => $query_params
                ));

How can i fix this?

like image 566
emrez Avatar asked Oct 27 '25 09:10

emrez


1 Answers

I solved above mentioned problem using Guzzle query request params.

I changed the query params as below. Then I changed the value of the guzzle 'query'.

$query_params = [
            'test' => 'abc',
            'test2' => true,
            'limit' => 10,
            'item_id' => array('8159','123')
    ];
$response = $this->client->request('GET', $endpoint, [
                   'headers' => [
                        'X-API-KEY' => KEY
                   ],
                   'query' => Query::build($query_params)
            ]);
like image 187
emrez Avatar answered Oct 29 '25 00:10

emrez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!