How to do HTTP basic auth with Laravel and Guzzle
HTTP ClientSometimes getting the syntax right in Guzzle can be a challenge. This is a legacy article that show you how to do `basic auth` using Guzzle.
$client = new Client();
$response = $client->request(
'POST', /*instead of POST, you can use GET, PUT, DELETE, etc*/
$url,
[
'auth' => ['username', 'password'] /*if you don't need to use a password, just leave it null*/
]
);
echo $response->getBody();
For a more up to date example, see the Laravel HTTP Client.