Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\Http\Client->setCookies(array $cookies): void
Set the cookies for the HTTP request.
None
Set the cookies for the HTTP request.
Cookie values will be parsed through urlencode
. Must always be a key-value array.
$client->cookies
setCookies()
will overwrite any values previously set<?php
use Swoole\Coroutine\HTTP\Client;
Co\run(function()
{
$client = new Client('127.0.0.1', 80);
// Setup request headers
$client->setHeaders([
'Host' => "localhost",
"User-Agent" => 'Chrome/49.0.2587.3',
'Accept' => 'text/html,application/xhtml+xml,application/xml',
'Accept-Encoding' => 'gzip',
]);
$client->set(['timeout' => 1]);
// Setup cookies using an array, key-value format
$client->setCookies([
'a' => 'b',
'auth_token' => 'HdwejDNjdfweifjhHJfjjJdhUUe...',
]);
$client->get('/index.php');
echo $client->body;
$client->close();
});