After upgrading to Guzzle6, I can't figure out how to setup default query string for the Client.
I have the following:
$client = new \GuzzleHttp\Client( [
'base_uri' => 'http://api.example.org/',
'query' => ['key' => 'secretKey']
] );
$client->get( 'extract', ['query' => ['url' => $url]] );
In this request my default query sting key=secretKey is being ignored.
How can I make it work?
Guzzle v6 does not support default query strings within the client options. Middleware is required.
$handler = new HandlerStack();
$handler->setHandler(new CurlHandler());
//Add access token
$handler->unshift(Middleware::mapRequest(function(RequestInterface $request) {
return $request->withUri(Uri::withQueryValue($request->getUri(), 'key', 'value'));
}));
//Create client
$this->client = new Client([
'base_uri' => ''
'handler' => $handler
]);
See https://github.com/guzzle/guzzle/issues/1138 for source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With