Adding Query string params to a Guzzle GET request?
To add query string parameters to a GET request using Guzzle, you can use the query
option when creating the request. For example:
<?php
$client = new GuzzleHttp\Client();
$response = $client->request('GET', 'http://example.com', [
'query' => [
'param1' => 'value1',
'param2' => 'value2',
],
]);
Watch a video course
Learn object oriented PHP
This will send a GET request to "http://example.com?param1=value1¶m2=value2".
You can also use the query
method on a request object to add query string parameters to an existing request. For example:
<?php
$request = $client->createRequest('GET', 'http://example.com');
$request->query->set('param1', 'value1');
$request->query->set('param2', 'value2');
$response = $client->send($request);