Can anyone explain how to add the Authorization Header within Guzzle? I can see the code below works for adding the username & password but in my instance I just want to add the Authorization header itself
$client->request('GET', '/get', ['auth' => ['username', 'password']
The Basic Authorization header I want to add to my GET request :-
Basic aGdkZQ1vOjBmNmFmYzdhMjhiMjcwZmE4YjEwOTQwMjc2NGQ3NDgxM2JhMjJkZjZlM2JlMzU5MTVlNGRkMTVlMGJlMWFiYmI=
I don't know how I missed reading that you were looking for the Basic auth header, but nonetheless hope this helps somewhat. If you are just looking to add the Authorization header, that should be pretty easy.
// Set various headers on a request
$client->request('GET', '/get', [
'headers' => [
'Authorization' => 'PUT WHATEVER YOU WANT HERE'
]
]);
I build up my request in Guzzle piece by piece so I use the following:
$client = new GuzzleHttp\Client();
$request = $client->createRequest('GET', '/get');
$request->addHeader('X-Authorization', 'OAuth realm=<OAUTH STUFF HERE>');
$resp = $client->send($request);
Hope that helps. Also, make sure to include the version of Libraries you are using in the future as syntax changes depending on your version.