Swoole\Coroutine\Http\Client->get(...)

Declaration

<?php
Swoole\Coroutine\Http\Client->get(string $path): void

Parameters

path

The URL path to send a GET request to. For example /user/account or /index.php. Only set the path here not the protocol or domain name like http://domain.

Return

None


Description

Initiate a HTTP client GET request using the specified URL path.

When you use this method it will switch to use GET for you, no need to use setMethod


Example

<?php
use Swoole\Coroutine\Http\Client;

Co\run(function()
{
    $client = new Client('127.0.0.1', 80);

    $client->setHeaders([
        'Host' => 'localhost',
        'User-Agent' => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);

    // First GET request
    $client->get('/home/contact');

    var_dump($client->body);

    // Second GET request
    $client->get('/index.php');

    var_dump($client->body);

    $client->close();
});