<?php
Swoole\Coroutine\Http\Client->setBasicAuth(string $username, string $password)
The username for HTTP basic auth.
The password for HTTP basic auth.
Set the HTTP basic auth username and password for the HTTP request.
<?php
use Swoole\Coroutine\HTTP\Client;
Co\run(function() {
$cli = new Client('127.0.0.1', 80);
$cli->setHeaders([
'Host' => "localhost",
"User-Agent" => 'Chrome/49.0.2587.3',
'Accept' => 'text/html,application/xhtml+xml,application/xml',
'Accept-Encoding' => 'gzip',
]);
$cli->set([ 'timeout' => 1]);
$cli->setBasicAuth('user', 'pass');
$cli->get('/index.php');
echo $cli->body;
$cli->close();
});