- Summary
- Associative array of headers to add to the request. Each key is thename of a header, and each value is a string or array of stringsrepresenting the header field values.
- Types
- array
- Defaults
- None
- Constant
- $client = new GuzzleHttp\Client(['headers' => ['X-Foo' => 'Bar']]);
-
- // Will send a request with the X-Foo header.
- $client->request('GET', '/get');
-
- // Sets the X-Foo header to "test", which prevents the default header
- $client->request('GET', '/get', ['headers' => ['X-Foo' => 'test']]);
-
- // Will disable adding in default headers.
- $client->request('GET', '/get', ['headers' => null]);
-
- // Will not overwrite the X-Foo header because it is in the message.
- $request = new Request('GET', 'http://foo.com', ['X-Foo' => 'test']);
- $client->send($request);
-
- // Will overwrite the X-Foo header with the request option provided in the
- // send method.
- use GuzzleHttp\Psr7\Request;
- $client->send($request, ['headers' => ['X-Foo' => 'overwrite']]);