Associative array of headers to add to the request. Each key is the name of a header, and each value is a string or array of strings representing the header field values.

    Types

    Defaults

    None

    Headers may be added as default options when creating a client. When headers are used as default options, they are only applied if the request being created does not already contain the specific header. This includes both requests passed to the client in the send() and sendAsync() methods, and requests created by the client (e.g., request() and requestAsync()).

    1. $client = new GuzzleHttp\Client(['headers' => ['X-Foo' => 'Bar']]);
    2. // Will send a request with the X-Foo header.
    3. $client->request('GET', '/get');
    4. // Sets the X-Foo header to "test", which prevents the default header
    5. $client->request('GET', '/get', ['headers' => ['X-Foo' => 'test']]);
    6. // Will disable adding in default headers.
    7. $client->request('GET', '/get', ['headers' => null]);
    8. // Will not overwrite the X-Foo header because it is in the message.
    9. $request = new Request('GET', 'http://foo.com', ['X-Foo' => 'test']);
    10. $client->send($request);
    11. // Will overwrite the X-Foo header with the request option provided in the
    12. // send method.
    13. use GuzzleHttp\Psr7\Request;
    14. $client->send($request, ['headers' => ['X-Foo' => 'overwrite']]);