Closed Halfi closed 8 years ago
I believe you should be able to achieve this using a handler. You can find more info on them in the guzzle docs.
It might look something like:
function add_header($header, $value)
{
return function (callable $handler) use ($header, $value) {
return function (
RequestInterface $request,
array $options
) use ($handler, $header, $value) {
$request = $request->withHeader($header, $value);
return $handler($request, $options);
};
};
}
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(add_header('Authorization', 'Basic QWxhZGRpbjpPcGVuU2VzYW1l'));
$client = Client::factory('http://localhost:8000', ['handler' => $stack]);
Thanks, but I'm find more simple way without handler callback:
raze\GuzzleHttp\JsonRpc\Client::factory(
'http://localhost:8000',
[
'auth' => ['user', 'secret']
]
);
It's work with Guzzle 6. If guzzle 5 there are some different way:
\Graze\GuzzleHttp\JsonRpc\Client::factory(
'http://localhost:8000',
[
'defaults' => [
'auth' => ['user', 'secret']
]
]
);
Even better! Thanks for sharing your solution.
At now haven't way to set Guzzle headers. I can't send request with basic auth.