When I run the following code (using the latest Guzzle, v6), the URL that gets requested is http://example.com/foobar?foo=bar
dropping the boo=far
from the request.
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar?boo=far');
$response = $guzzle_http_client->send($request);
When I run the following code, passing boo=far
instead as part of the Client::send()
method, the URL that gets requested is http://example.com/foobar?boo=far
$guzzle_http_client = new GuzzleHttp\Client([
'base_uri' => 'http://example.com/',
'query' => [
'foo' => 'bar'
],
]);
$request = new \GuzzleHttp\Psr7\Request('GET', 'foobar');
$response = $guzzle_http_client->send($request, ['query' => ['boo' => 'far']]);
Of course, the URL that I want to be requested is:
http://example.com/foobar?foo=bar&bar=foo
How do I make Guzzle combine default client query string parameters with request-specific parameters?
You can try to get default 'query' options using 'getConfig' method and then merge them with new 'query' options, here an example:
And then you can easy send a GET request:
Additional info you can find here Request Options