Query String Parameters

You can provide query string parameters with a request in several ways.

You can set query string parameters in the request’s URI:

  1. $response = $client->request('GET', 'http://httpbin.org?foo=bar');

You can specify the query string parameters using the query request option as an array.

  1. $client->request('GET', 'http://httpbin.org', [
  2. 'query' => ['foo' => 'bar']
  3. ]);

Providing the option as an array will use PHP’s http_build_query function to format the query string.

And finally, you can provide the query request option as a string.

  1. $client->request('GET', 'http://httpbin.org', ['query' => 'foo=bar']);