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

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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 OpenSwoole\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();
});
Last updated on September 1, 2022